1010from ..http20 .connection import HTTP20Connection
1111from ..tls import H2_NPN_PROTOCOLS , H2C_PROTOCOL
1212
13+
1314class HTTPConnection (object ):
1415 """
1516 An object representing a single HTTP connection to a server.
@@ -24,26 +25,27 @@ class HTTPConnection(object):
2425 :param host: The host to connect to. This may be an IP address or a
2526 hostname, and optionally may include a port: for example,
2627 ``'http2bin.org'``, ``'http2bin.org:443'`` or ``'127.0.0.1'``.
27- :param port: (optional) The port to connect to. If not provided and one also
28- isn't provided in the ``host`` parameter, defaults to 443 .
28+ :param port: (optional) The port to connect to. If not provided and one
29+ also isn't provided in the ``host`` parameter, defaults to 80 .
2930 :param secure: (optional) Whether the request should use TLS.
3031 Defaults to ``False`` for most requests, but to ``True`` for any
3132 request issued to port 443.
3233 :param window_manager: (optional) The class to use to manage flow control
3334 windows. This needs to be a subclass of the
34- :class:`BaseFlowControlManager <hyper.http20.window.BaseFlowControlManager>`.
35- If not provided,
35+ :class:`BaseFlowControlManager
36+ <hyper.http20.window.BaseFlowControlManager>`. If not provided,
3637 :class:`FlowControlManager <hyper.http20.window.FlowControlManager>`
3738 will be used.
3839 :param enable_push: (optional) Whether the server is allowed to push
3940 resources to the client (see
4041 :meth:`get_pushes() <hyper.HTTP20Connection.get_pushes>`).
4142 :param ssl_context: (optional) A class with custom certificate settings.
4243 If not provided then hyper's default ``SSLContext`` is used instead.
43- :param proxy_host: (optional) The proxy to connect to. This can be an IP address
44- or a host name and may include a port.
45- :param proxy_port: (optional) The proxy port to connect to. If not provided
46- and one also isn't provided in the ``proxy`` parameter, defaults to 8080.
44+ :param proxy_host: (optional) The proxy to connect to. This can be an IP
45+ address or a host name and may include a port.
46+ :param proxy_port: (optional) The proxy port to connect to. If not provided
47+ and one also isn't provided in the ``proxy`` parameter, defaults to
48+ 8080.
4749 """
4850 def __init__ (self ,
4951 host ,
@@ -59,12 +61,12 @@ def __init__(self,
5961 self ._host = host
6062 self ._port = port
6163 self ._h1_kwargs = {
62- 'secure' : secure , 'ssl_context' : ssl_context ,
63- 'proxy_host' : proxy_host , 'proxy_port' : proxy_port
64+ 'secure' : secure , 'ssl_context' : ssl_context ,
65+ 'proxy_host' : proxy_host , 'proxy_port' : proxy_port
6466 }
6567 self ._h2_kwargs = {
6668 'window_manager' : window_manager , 'enable_push' : enable_push ,
67- 'secure' : secure , 'ssl_context' : ssl_context ,
69+ 'secure' : secure , 'ssl_context' : ssl_context ,
6870 'proxy_host' : proxy_host , 'proxy_port' : proxy_port
6971 }
7072
@@ -76,7 +78,7 @@ def __init__(self,
7678 self ._host , self ._port , ** self ._h1_kwargs
7779 )
7880
79- def request (self , method , url , body = None , headers = {} ):
81+ def request (self , method , url , body = None , headers = None ):
8082 """
8183 This will send a request to the server using the HTTP request method
8284 ``method`` and the selector ``url``. If the ``body`` argument is
@@ -93,6 +95,9 @@ def request(self, method, url, body=None, headers={}):
9395 :returns: A stream ID for the request, or ``None`` if the request is
9496 made over HTTP/1.1.
9597 """
98+
99+ headers = headers or {}
100+
96101 try :
97102 return self ._conn .request (
98103 method = method , url = url , body = body , headers = headers
0 commit comments