◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
10 changes: 10 additions & 0 deletions Lib/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,8 @@ def __init__(self, host, port=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,

(self.host, self.port) = self._get_hostport(host, port)

# This is stored as an instance variable to allow unit
# tests to replace it with a suitable mockup
self._create_connection = socket.create_connection
Expand Down @@ -1215,6 +1217,14 @@ def _validate_path(self, url):
raise InvalidURL(f"URL can't contain control characters. {url!r} "
f"(found at least {match.group()!r})")

def putheader(self, header, *values):
"""Send a request header line to the server.

Expand Down
13 changes: 12 additions & 1 deletion Lib/test/test_httplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ def run_server():
thread.join()
self.assertEqual(result, b"proxied data\n")

def test_putrequest_override_validation(self):
"""
It should be possible to override the default validation
behavior in putrequest (bpo-38216).
Expand All @@ -1145,6 +1145,17 @@ def _validate_path(self, url):
conn.sock = FakeSocket('')
conn.putrequest('GET', '/\x00')

def test_putrequest_override_encoding(self):
"""
It should be possible to override the default encoding
Expand Down
36 changes: 34 additions & 2 deletions Lib/test/test_urllib.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def test_willclose(self):
self.unfakehttp()

@unittest.skipUnless(ssl, "ssl module required")
def test_url_with_control_char_rejected(self):
for char_no in list(range(0, 0x21)) + [0x7f]:
char = chr(char_no)
schemeless_url = f"//localhost:7777/test{char}/"
Expand All @@ -358,7 +358,7 @@ def test_url_with_control_char_rejected(self):
self.unfakehttp()

@unittest.skipUnless(ssl, "ssl module required")
def test_url_with_newline_header_injection_rejected(self):
self.fakehttp(b"HTTP/1.1 200 OK\r\n\r\nHello.")
host = "localhost:7777?a=1 HTTP/1.1\r\nX-injected: header\r\nTEST: 123"
schemeless_url = "//" + host + ":8080/test/?test=a"
Expand All @@ -383,6 +383,38 @@ def test_url_with_newline_header_injection_rejected(self):
finally:
self.unfakehttp()

def test_read_0_9(self):
# "0.9" response accepted (but not "simple responses" without
# a status line)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Toggle all file notes Toggle all file annotations