Skip to content

Commit ca2147d

Browse files
brentrubrentru
brentru
authored and
brentru
committed
refactor request method to use parse_headers
1 parent f77d713 commit ca2147d

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

adafruit_requests.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -224,23 +224,13 @@ def request(method, url, data=None, json=None, headers=None, stream=False, timeo
224224
reason = ""
225225
if len(line) > 2:
226226
reason = line[2].rstrip()
227-
while True:
228-
line = sock.readline()
229-
if not line or line == b"\r\n":
230-
break
231-
232-
# print("**line: ", line)
233-
title, content = line.split(b": ", 1)
234-
if title and content:
235-
title = str(title.lower(), "utf-8")
236-
content = str(content, "utf-8")
237-
resp.headers[title] = content
238-
239-
if line.startswith(b"Transfer-Encoding:"):
240-
if b"chunked" in line:
241-
raise ValueError("Unsupported " + line)
242-
elif line.startswith(b"Location:") and not 200 <= status <= 299:
243-
raise NotImplementedError("Redirects not yet supported")
227+
self.parse_headers(sock)
228+
229+
if line.startswith(b"Transfer-Encoding:"):
230+
if b"chunked" in line:
231+
raise ValueError("Unsupported " + line)
232+
elif line.startswith(b"Location:") and not 200 <= status <= 299:
233+
raise NotImplementedError("Redirects not yet supported")
244234

245235
except:
246236
sock.close()

0 commit comments

Comments
 (0)