Skip to content

Commit 59a467e

Browse files
authored
Merge pull request #7 from brentru/refactor_req
Refactor request method to use parse_headers
2 parents f77d713 + 07fef5e commit 59a467e

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

adafruit_requests.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -224,23 +224,12 @@ 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+
resp.headers = parse_headers(sock)
228+
if resp.headers.get("transfer-encoding"):
229+
if "chunked" in resp.headers.get("transfer-encoding"):
230+
raise ValueError("Unsupported " + resp.headers.get("transfer-encoding"))
231+
elif resp.headers.get("location") and not 200 <= status <= 299:
232+
raise NotImplementedError("Redirects not yet supported")
244233

245234
except:
246235
sock.close()

0 commit comments

Comments
 (0)