Example #1
0
 def __init__(self,
              authority,
              receiver=None,
              rx_buffer_size=None,
              **headers):
     user_info, host, port = parse_authority(authority)
     if user_info:
         headers[b"Authorization"] = basic_auth(user_info)
     if port:
         headers[b"Host"] = host + b":" + bstr(port)
     else:
         headers[b"Host"] = host
     super(HTTP, self).__init__((host, port or HTTP_PORT), receiver,
                                rx_buffer_size, headers)
     self.data_limit = b"\r\n"
     self.requests = deque()
     self.responses = deque()
     self.response_handler = self.on_status_line
Example #2
0
 def test_can_parse_full_authority(self):
     user_info, host, port = parse_authority(b"[email protected]:6789")
     assert user_info == b"bob"
     assert host == b"example.com"
     assert port == 6789
Example #3
0
 def test_can_parse_email_user_host_authority(self):
     user_info, host, port = parse_authority(b"[email protected]@example.com")
     assert user_info == b"*****@*****.**"
     assert host == b"example.com"
     assert port is None
Example #4
0
 def test_can_parse_host_port_authority(self):
     user_info, host, port = parse_authority(b"example.com:6789")
     assert user_info is None
     assert host == b"example.com"
     assert port == 6789
Example #5
0
 def test_can_parse_empty_authority(self):
     user_info, host, port = parse_authority(b"")
     assert user_info is None
     assert host == b""
     assert port is None
Example #6
0
 def test_can_parse_none_authority(self):
     user_info, host, port = parse_authority(None)
     assert user_info is None
     assert host is None
     assert port is None