Module: HTTPX::Plugins::Proxy::InstanceMethods
- Defined in:
- lib/httpx/plugins/proxy.rb,
sig/plugins/proxy.rbs
Instance Method Summary collapse
- #find_connection(request_uri, selector, options) ⇒ Object
- #proxy_error?(_request, response, options) ⇒ Boolean
Instance Method Details
#find_connection(request_uri, selector, options) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/httpx/plugins/proxy.rb', line 164 def find_connection(request_uri, selector, ) return super unless .respond_to?(:proxy) if (next_proxy = request_uri.find_proxy) return super(request_uri, selector, .merge(proxy: Parameters.new(uri: next_proxy))) end proxy = .proxy return super unless proxy next_proxy = proxy.uri raise ProxyError, "Failed to connect to proxy" unless next_proxy raise ProxyError, "#{next_proxy.scheme}: unsupported proxy protocol" unless .supported_proxy_protocols.include?(next_proxy.scheme) if (no_proxy = proxy.no_proxy) no_proxy = no_proxy.join(",") if no_proxy.is_a?(Array) unless no_proxy != "*" && # NO_PROXY=* bypasses proxy use URI::Generic.use_proxy?(request_uri.host, next_proxy.host, next_proxy.port, no_proxy) # TODO: setting proxy to nil leaks the connection object in the pool return super(request_uri, selector, .merge(proxy: nil)) end end super(request_uri, selector, .merge(proxy: proxy)) end |
#proxy_error?(_request, response, options) ⇒ Boolean
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/httpx/plugins/proxy.rb', line 225 def proxy_error?(_request, response, ) return false unless .proxy error = response.error case error when NativeResolveError proxy_uri = URI(.proxy.uri) unresolved_host = error.host # failed resolving proxy domain unresolved_host == proxy_uri.host when ResolveError proxy_uri = URI(.proxy.uri) error..end_with?(proxy_uri.to_s) when ProxyConnectionError # timeout errors connecting to proxy true else false end end |