Skip to content

Refactor request method to use parse_headers #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 2, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 " + str(line[0]))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, missed this one on my first pass. I think this is supposed to be the transfer encoding header value in the exception string.

elif resp.headers.get("location") and not 200 <= status <= 299:
raise NotImplementedError("Redirects not yet supported")

except:
sock.close()
Expand Down