rfwtools.network.SSLContextAdapter

class rfwtools.network.SSLContextAdapter(pool_connections=10, pool_maxsize=10, max_retries=0, pool_block=False)[source]

Bases: HTTPAdapter

An HTTPAdapter that loads the default system SSL trust store

This is needed since the requests module ships with its own CA cert store that does not include the JLab PKI

__init__(pool_connections=10, pool_maxsize=10, max_retries=0, pool_block=False)

Methods

__init__([pool_connections, pool_maxsize, ...])

add_headers(request, **kwargs)

Add any headers needed by the connection.

build_response(req, resp)

Builds a Response object from a urllib3 response.

cert_verify(conn, url, verify, cert)

Verify a SSL certificate.

close()

Disposes of any internal state.

get_connection(url[, proxies])

Returns a urllib3 connection for the given URL.

init_poolmanager(*args, **kwargs)

Overrides the parent method to include call to load_default_certs()

proxy_headers(proxy)

Returns a dictionary of the headers to add to any request sent through a proxy.

proxy_manager_for(proxy, **proxy_kwargs)

Return urllib3 ProxyManager for the given proxy.

request_url(request, proxies)

Obtain the url to use when making the final request.

send(request[, stream, timeout, verify, ...])

Sends PreparedRequest object.

add_headers(request, **kwargs)

Add any headers needed by the connection. As of v2.0 this does nothing by default, but is left for overriding by users that subclass the HTTPAdapter.

This should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.

Parameters:
  • request – The PreparedRequest to add headers to.

  • kwargs – The keyword arguments from the call to send().

build_response(req, resp)

Builds a Response object from a urllib3 response. This should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter

Parameters:
  • req – The PreparedRequest used to generate the response.

  • resp – The urllib3 response object.

Return type:

requests.Response

cert_verify(conn, url, verify, cert)

Verify a SSL certificate. This method should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.

Parameters:
  • conn – The urllib3 connection object associated with the cert.

  • url – The requested URL.

  • verify – Either a boolean, in which case it controls whether we verify the server’s TLS certificate, or a string, in which case it must be a path to a CA bundle to use

  • cert – The SSL certificate to verify.

close()

Disposes of any internal state.

Currently, this closes the PoolManager and any active ProxyManager, which closes any pooled connections.

get_connection(url, proxies=None)

Returns a urllib3 connection for the given URL. This should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.

Parameters:
  • url – The URL to connect to.

  • proxies – (optional) A Requests-style dictionary of proxies used on this request.

Return type:

urllib3.ConnectionPool

init_poolmanager(*args, **kwargs)[source]

Overrides the parent method to include call to load_default_certs()

proxy_headers(proxy)

Returns a dictionary of the headers to add to any request sent through a proxy. This works with urllib3 magic to ensure that they are correctly sent to the proxy, rather than in a tunnelled request if CONNECT is being used.

This should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.

Parameters:

proxy – The url of the proxy being used for this request.

Return type:

dict

proxy_manager_for(proxy, **proxy_kwargs)

Return urllib3 ProxyManager for the given proxy.

This method should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.

Parameters:
  • proxy – The proxy to return a urllib3 ProxyManager for.

  • proxy_kwargs – Extra keyword arguments used to configure the Proxy Manager.

Returns:

ProxyManager

Return type:

urllib3.ProxyManager

request_url(request, proxies)

Obtain the url to use when making the final request.

If the message is being sent through a HTTP proxy, the full URL has to be used. Otherwise, we should only use the path portion of the URL.

This should not be called from user code, and is only exposed for use when subclassing the HTTPAdapter.

Parameters:
  • request – The PreparedRequest being sent.

  • proxies – A dictionary of schemes or schemes and hosts to proxy URLs.

Return type:

str

send(request, stream=False, timeout=None, verify=True, cert=None, proxies=None)

Sends PreparedRequest object. Returns Response object.

Parameters:
  • request – The PreparedRequest being sent.

  • stream – (optional) Whether to stream the request content.

  • timeout (float or tuple or urllib3 Timeout object) – (optional) How long to wait for the server to send data before giving up, as a float, or a (connect timeout, read timeout) tuple.

  • verify – (optional) Either a boolean, in which case it controls whether we verify the server’s TLS certificate, or a string, in which case it must be a path to a CA bundle to use

  • cert – (optional) Any user-provided SSL certificate to be trusted.

  • proxies – (optional) The proxies dictionary to apply to the request.

Return type:

requests.Response