Skip to content

Commit

Permalink
Merge pull request #7 from brentru/refactor_req
Browse files Browse the repository at this point in the history
Refactor request method to use parse_headers
  • Loading branch information
brentru authored Aug 2, 2019
2 parents f77d713 + 07fef5e commit 59a467e
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions adafruit_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,23 +224,12 @@ def request(method, url, data=None, json=None, headers=None, stream=False, timeo
reason = ""
if len(line) > 2:
reason = line[2].rstrip()
while True:
line = sock.readline()
if not line or line == b"\r\n":
break

# print("**line: ", line)
title, content = line.split(b": ", 1)
if title and content:
title = str(title.lower(), "utf-8")
content = str(content, "utf-8")
resp.headers[title] = content

if line.startswith(b"Transfer-Encoding:"):
if b"chunked" in line:
raise ValueError("Unsupported " + line)
elif line.startswith(b"Location:") and not 200 <= status <= 299:
raise NotImplementedError("Redirects not yet supported")
resp.headers = parse_headers(sock)
if resp.headers.get("transfer-encoding"):
if "chunked" in resp.headers.get("transfer-encoding"):
raise ValueError("Unsupported " + resp.headers.get("transfer-encoding"))
elif resp.headers.get("location") and not 200 <= status <= 299:
raise NotImplementedError("Redirects not yet supported")

except:
sock.close()
Expand Down

0 comments on commit 59a467e

Please sign in to comment.