urllib.urequest: Avoid allocating memory when issuing request.

Memory will still be allocated when parsing response, but this already
saves 164 bytes of memory traffic (x64).
pull/76/merge
Paul Sokolovsky 2016-06-11 00:07:54 +03:00
rodzic 52ac454ef7
commit d036673d7b
1 zmienionych plików z 9 dodań i 3 usunięć

Wyświetl plik

@ -27,11 +27,17 @@ def urlopen(url, data=None, method="GET"):
if proto == "https:":
s = ussl.wrap_socket(s)
req = b"%s /%s HTTP/1.0\r\nHost: %s\r\n" % (method, path, host)
s.write(req)
s.write(method)
s.write(b" /")
s.write(path)
s.write(b" HTTP/1.0\r\nHost: ")
s.write(host)
s.write(b"\r\n")
if data:
req = b"Content-Length: %d\r\n" % len(data)
s.write(b"Content-Length: ")
s.write(str(len(data)))
s.write(b"\r\n")
s.write(b"\r\n")
if data:
s.write(data)