diff --git a/adafruit_requests.py b/adafruit_requests.py index 07e5d40..dfb32a7 100755 --- a/adafruit_requests.py +++ b/adafruit_requests.py @@ -250,10 +250,26 @@ def request(method, url, data=None, json=None, headers=None, stream=False, timeo resp.reason = reason return resp - -# pylint: enable=too-many-branches, too-many-statements, unused-argument -# pylint: enable=too-many-arguments, too-many-locals - +def parse_headers(sock): + """ + Parses the header portion of an HTTP request/response from the socket. + Expects first line of HTTP request/response to have been read already + return: header dictionary + rtype: Dict + """ + headers = {} + 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') + headers[title] = content + return headers def head(url, **kw): """Send HTTP HEAD request"""