Backends

class urllib3.backend.BaseBackend(host, port=None, timeout=-1, source_address=None, blocksize=131072, *, socket_options=[(6, 1, 1, 'tcp')], disabled_svn=None, preemptive_quic_cache=None)

Bases: object

The goal here is to detach ourselves from the http.client package. At first, we’ll strictly follow the methods in http.client.HTTPConnection. So that we would be able to implement other backend without disrupting the actual code base. Extend that base class in order to ship another backend with urllib3.

Parameters:
  • host (str)

  • port (int | None)

  • timeout (int | float | None)

  • source_address (tuple[str, int] | None)

  • blocksize (int)

  • socket_options (_TYPE_SOCKET_OPTIONS | None)

  • disabled_svn (set[HttpVersion] | None)

  • preemptive_quic_cache (QuicPreemptiveCacheType | None)

close()

End the connection, do some reinit, closing of fd, etc…

Return type:

None

default_socket_options: ClassVar[_TYPE_SOCKET_OPTIONS] = [(6, 1, 1, 'tcp')]

Disable Nagle’s algorithm by default.

endheaders(message_body=None, *, encode_chunked=False, expect_body_afterward=False)

This method conclude the request context construction.

Parameters:
  • message_body (bytes | None)

  • encode_chunked (bool)

  • expect_body_afterward (bool)

Return type:

ResponsePromise | None

getresponse(*, promise=None)

Fetch the HTTP response. You SHOULD not retrieve the body in that method, it SHOULD be done in the LowLevelResponse, so it enable stream capabilities and remain efficient.

Parameters:

promise (ResponsePromise | None)

Return type:

LowLevelResponse

is_verified: bool = False

Whether this connection verifies the host’s certificate.

putheader(header, *values)

For a single header name, assign one or multiple value. This method is called right after putrequest() for each entries.

Parameters:
Return type:

None

putrequest(method, url, skip_host=False, skip_accept_encoding=False)

It is the first method called, setting up the request initial context.

Parameters:
Return type:

None

response_class

alias of LowLevelResponse

send(data, *, eot=False)

The send() method SHOULD be invoked after calling endheaders() if and only if the request context specify explicitly that a body is going to be sent.

Parameters:
Return type:

ResponsePromise | None

set_tunnel(host, port=None, headers=None, scheme='http')

Prepare the connection to set up a tunnel. Does NOT actually do the socket and http connect. Here host:port represent the target (final) server and not the intermediary.

Parameters:
Return type:

None

class urllib3.backend.hface.HfaceBackend(host, port=None, timeout=-1, source_address=None, blocksize=131072, *, socket_options=[(6, 1, 1, 'tcp')], disabled_svn=None, preemptive_quic_cache=None)

Bases: BaseBackend

Parameters:
  • host (str)

  • port (int | None)

  • timeout (int | float | None)

  • source_address (tuple[str, int] | None)

  • blocksize (int)

  • socket_options (_TYPE_SOCKET_OPTIONS | None)

  • disabled_svn (set[HttpVersion] | None)

  • preemptive_quic_cache (QuicPreemptiveCacheType | None)

close()

End the connection, do some reinit, closing of fd, etc…

Return type:

None

endheaders(message_body=None, *, encode_chunked=False, expect_body_afterward=False)

This method conclude the request context construction.

Parameters:
  • message_body (bytes | None)

  • encode_chunked (bool)

  • expect_body_afterward (bool)

Return type:

ResponsePromise | None

getresponse(*, promise=None, early_response_callback=None)

Fetch the HTTP response. You SHOULD not retrieve the body in that method, it SHOULD be done in the LowLevelResponse, so it enable stream capabilities and remain efficient.

Parameters:
Return type:

LowLevelResponse

putheader(header, *values)

For a single header name, assign one or multiple value. This method is called right after putrequest() for each entries.

Parameters:
Return type:

None

putrequest(method, url, skip_host=False, skip_accept_encoding=False)

Internally fhace translate this into what putrequest does. e.g. initial trame.

Parameters:
Return type:

None

send(data, *, eot=False)

We might be receiving a chunk constructed downstream

Parameters:
Return type:

ResponsePromise | None

set_tunnel(host, port=None, headers=None, scheme='http')

Prepare the connection to set up a tunnel. Does NOT actually do the socket and http connect. Here host:port represent the target (final) server and not the intermediary.

Parameters:
Return type:

None

class urllib3.backend.HttpVersion(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Describe possible SVN protocols that can be supported.

class urllib3.backend.ResponsePromise(conn, stream_id, request_headers, **parameters)
Parameters:
urllib3.backend.QuicPreemptiveCacheType

alias of MutableMapping[Tuple[str, int], Tuple[str, int] | None]

class urllib3.backend.ConnectionInfo
certificate_der: bytes | None

The SSL certificate presented by the remote peer (not the proxy)

cipher: str | None

The TLS cipher used to secure the exchanges (not the proxy)

destination_address: tuple[str, int] | None

The IP address used to reach the remote peer (not the proxy), that was yield by your resolver.

established_latency: timedelta | None

Time taken to establish the connection

http_version: HttpVersion | None

HTTP protocol used with the remote peer (not the proxy)

issuer_certificate_der: bytes | None

The SSL issuer certificate for the remote peer certificate (not the proxy)

request_sent_latency: timedelta | None

Time taken to encode and send the whole request through the socket.

resolution_latency: timedelta | None

Time taken to resolve a domain name into a reachable IP address.

tls_handshake_latency: timedelta | None

The time taken to reach a complete TLS liaison between the remote peer and us. (not the proxy)

tls_version: TLSVersion | None

The TLS revision used (not the proxy)