kopia lustrzana https://github.com/micropython/micropython-lib
urequests: If error happens while parsing response headers, close socket.
Because otherwise, user doesn't get any response object, so cannot close socket, and it leaks.pull/208/head
rodzic
7a469b229e
commit
586ae64cb0
|
@ -50,7 +50,9 @@ def request(method, url, data=None, json=None, headers={}, stream=None):
|
|||
|
||||
ai = usocket.getaddrinfo(host, port)
|
||||
addr = ai[0][-1]
|
||||
|
||||
s = usocket.socket()
|
||||
try:
|
||||
s.connect(addr)
|
||||
if proto == "https:":
|
||||
s = ussl.wrap_socket(s, server_hostname=host)
|
||||
|
@ -87,6 +89,9 @@ def request(method, url, data=None, json=None, headers={}, stream=None):
|
|||
raise ValueError("Unsupported " + l)
|
||||
elif l.startswith(b"Location:") and not 200 <= status <= 299:
|
||||
raise NotImplementedError("Redirects not yet supported")
|
||||
except OSError:
|
||||
s.close()
|
||||
raise
|
||||
|
||||
resp = Response(s)
|
||||
resp.status_code = status
|
||||
|
|
Ładowanie…
Reference in New Issue