Primary HTTP Interface¶
-
class
hyper.
HTTPConnection
(host, port=None, secure=None, window_manager=None, enable_push=False, ssl_context=None, **kwargs)¶ An object representing a single HTTP connection to a server.
This object behaves similarly to the Python standard library’s
HTTPConnection
object, with a few critical differences.Most of the standard library’s arguments to the constructor are not supported by hyper. Most optional parameters apply to either HTTP/1.1 or HTTP/2.
Parameters: - host – The host to connect to. This may be an IP address or a
hostname, and optionally may include a port: for example,
'http2bin.org'
,'http2bin.org:443'
or'127.0.0.1'
. - port – (optional) The port to connect to. If not provided and one also
isn’t provided in the
host
parameter, defaults to 443. - secure – (optional) Whether the request should use TLS.
Defaults to
False
for most requests, but toTrue
for any request issued to port 443. - window_manager – (optional) The class to use to manage flow control
windows. This needs to be a subclass of the
BaseFlowControlManager
. If not provided,FlowControlManager
will be used. - enable_push – (optional) Whether the server is allowed to push
resources to the client (see
get_pushes()
). - ssl_context – (optional) A class with custom certificate settings.
If not provided then hyper’s default
SSLContext
is used instead.
-
get_response
()¶ Returns a response object.
-
request
(method, url, body=None, headers={})¶ This will send a request to the server using the HTTP request method
method
and the selectorurl
. If thebody
argument is present, it should be string or bytes object of data to send after the headers are finished. Strings are encoded as UTF-8. To use other encodings, pass a bytes object. The Content-Length header is set to the length of the body field.Parameters: - method – The request method, e.g.
'GET'
. - url – The URL to contact, e.g.
'/path/segment'
. - body – (optional) The request body to send. Must be a bytestring or a file-like object.
- headers – (optional) The headers to send on the request.
Returns: A stream ID for the request, or
None
if the request is made over HTTP/1.1.- method – The request method, e.g.
- host – The host to connect to. This may be an IP address or a
hostname, and optionally may include a port: for example,