Skip to content

Commit 52ac454

Browse files
author
Paul Sokolovsky
committed
urllib.urequest: Avoid allocating long semi-duplicate strings.
1 parent 5cd5581 commit 52ac454

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

urllib.urequest/urllib/urequest.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ def urlopen(url, data=None, method="GET"):
2626
s.connect(addr)
2727
if proto == "https:":
2828
s = ussl.wrap_socket(s)
29-
if data:
30-
req = b"%s /%s HTTP/1.0\r\nHost: %s\r\nContent-Length: %d\r\n\r\n" % (method, path, host, len(data))
31-
else:
32-
req = b"%s /%s HTTP/1.0\r\nHost: %s\r\n\r\n" % (method, path, host)
29+
30+
req = b"%s /%s HTTP/1.0\r\nHost: %s\r\n" % (method, path, host)
3331
s.write(req)
32+
33+
if data:
34+
req = b"Content-Length: %d\r\n" % len(data)
35+
s.write(b"\r\n")
3436
if data:
3537
s.write(data)
3638

0 commit comments

Comments
 (0)