FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-159044: Restore string conversion for HTTP tunnel headers by SomSamantray · Pull Request #159167 · python/cpython · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 2 additions & 0 deletions Doc/library/http.client.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ HTTPConnection Objects
The *headers* argument should be a mapping of extra HTTP headers to send with
the CONNECT request.

Header values in the mapping are converted to strings before they are sent.

As HTTP/1.1 is used for HTTP CONNECT tunnelling request, `as per the RFC
<https://datatracker.ietf.org/doc/html/rfc7231#section-4.3.6>`_, a HTTP ``Host:``
header must be provided, matching the authority-form of the request target
Expand Down
4 changes: 2 additions & 2 deletions Lib/http/client.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1014,8 +1014,8 @@ def _tunnel(self):
self._http_vsn_str.encode("ascii"))
headers = [connect]
for header, value in self._tunnel_headers.items():
header_bytes = header.encode("latin-1")
value_bytes = value.encode("latin-1")
header_bytes = str(header).encode("latin-1")
value_bytes = str(value).encode("latin-1")
if not _is_legal_header_name(header_bytes):
raise ValueError('Invalid header name %r' % (header_bytes,))
if _is_illegal_header_value(value_bytes):
Expand Down
13 changes: 13 additions & 0 deletions Lib/test/test_httplib.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,19 @@ def test_invalid_tunnel_headers(self):
with self.assertRaisesRegex(ValueError, 'Invalid header'):
conn._tunnel() # Called in .connect()

def test_tunnel_headers_are_converted_to_strings(self):
conn = client.HTTPConnection('example.com')
conn.set_tunnel('tunnel', headers={
'None-Value': None,
'Integer-Value': 42,
})
conn.sock = FakeSocket('HTTP/1.1 200 Connection established\r\n\r\n')

conn._tunnel() # Called in .connect()

self.assertIn(b'None-Value: None\r\n', conn.sock.data)
self.assertIn(b'Integer-Value: 42\r\n', conn.sock.data)

def test_invalid_tunnel_host(self):
cases = (
'invalid\r.host',
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Restore string conversion of HTTP CONNECT tunnel header names and values.
Loading

Back | FazBrowse Home | New Git URL