| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -858,6 +858,7 @@ def __init__(self, host, port=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, | |||
| 858 | 858 | self._tunnel_host = None | |
| 859 | 859 | self._tunnel_port = None | |
| 860 | 860 | self._tunnel_headers = {} | |
| 861 | + self._proxy_response_headers = None | ||
| 861 | 862 | ||
| 862 | 863 | (self.host, self.port) = self._get_hostport(host, port) | |
| 863 | 864 | ||
@@ -944,21 +945,16 @@ def _tunnel(self): | |||
| 944 | 945 | try: | |
| 945 | 946 | (version, code, message) = response._read_status() | |
| 946 | 947 | ||
| 948 | + self._proxy_response_headers = parse_headers(response.fp) | ||
| 949 | + | ||
| 950 | + if self.debuglevel > 0: | ||
| 951 | + for hdr, val in self._proxy_response_headers.items(): | ||
| 952 | + print("header:", hdr + ":", val) | ||
| 953 | + | ||
| 947 | 954 | if code != http.HTTPStatus.OK: | |
| 948 | 955 | self.close() | |
| 949 | 956 | raise OSError(f"Tunnel connection failed: {code} {message.strip()}") | |
| 950 | - while True: | ||
| 951 | - line = response.fp.readline(_MAXLINE + 1) | ||
| 952 | - if len(line) > _MAXLINE: | ||
| 953 | - raise LineTooLong("header line") | ||
| 954 | - if not line: | ||
| 955 | - # for sites which EOF without sending a trailer | ||
| 956 | - break | ||
| 957 | - if line in (b'\r\n', b'\n', b''): | ||
| 958 | - break | ||
| 959 | 957 | ||
| 960 | - if self.debuglevel > 0: | ||
| 961 | - print('header:', line.decode()) | ||
| 962 | 958 | finally: | |
| 963 | 959 | response.close() | |
| 964 | 960 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2390,6 +2390,20 @@ def test_tunnel_debuglog(self): | |||
| 2390 | 2390 | lines = output.getvalue().splitlines() | |
| 2391 | 2391 | self.assertIn('header: {}'.format(expected_header), lines) | |
| 2392 | 2392 | ||
| 2393 | + def test_proxy_response_headers(self): | ||
| 2394 | + expected_header = ('X-Dummy', '1') | ||
| 2395 | + response_text = ( | ||
| 2396 | + 'HTTP/1.0 200 OK\r\n' | ||
| 2397 | + '{0}\r\n\r\n'.format(':'.join(expected_header)) | ||
| 2398 | + ) | ||
| 2399 | + | ||
| 2400 | + self.conn._create_connection = self._create_connection(response_text) | ||
| 2401 | + self.conn.set_tunnel('destination.com') | ||
| 2402 | + | ||
| 2403 | + self.conn.request('PUT', '/', '') | ||
| 2404 | + headers = self.conn._proxy_response_headers | ||
| 2405 | + self.assertIn(expected_header, headers.items()) | ||
| 2406 | + | ||
| 2393 | 2407 | def test_tunnel_leak(self): | |
| 2394 | 2408 | sock = None | |
| 2395 | 2409 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + Added attribute '_proxy_response_headers' to HTTPConnection class. This | ||
| 2 | + attribute contains the headers of the proxy server response to the CONNECT | ||
| 3 | + request. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments