)]}'
{"swift/common/utils.py":[{"author":{"_account_id":9107,"name":"Victor Stinner","email":"vstinner@redhat.com","username":"haypo"},"change_message_id":"2792b874475331b41cc702ddb6860bb41fafa819","unresolved":false,"context_lines":[{"line_number":3303,"context_line":"                break"},{"line_number":3304,"context_line":"            s \u003d line.split(\u0027:\u0027, 1)"},{"line_number":3305,"context_line":"            last_header \u003d s[0].lower()"},{"line_number":3306,"context_line":"            self.headers[last_header] \u003d s[1].strip()"},{"line_number":3307,"context_line":""},{"line_number":3308,"context_line":"    def getheader(self, header, default\u003dNone):"},{"line_number":3309,"context_line":"        return self.headers.get(header.lower(), default)"}],"source_content_type":"text/x-python","patch_set":1,"id":"da20952f_dc440648","line":3306,"updated":"2015-09-07 08:36:18.000000000","message":"Is doc_file a binary or a text file? If it\u0027s a binary file, this code is not compatible with Python 3.\n\nSuch code already exists in Python 3 stdlib: http.client.parse_headers(). On Python 2, there is httplib.HTTPMessage.readheaders(). Both functions stop parsing after the end of the headers, so the body is not read into memory.\n\nThese functions prevents the Python hash DoS: it raises an exception if the server sends more than 100 lines of headers.\n\nhttp.client.parse_headers() reuses email.parser.Parser() which is more secure because it\u0027s implement strict rules to parse headers (ex: error for missing header name).\n\nhttplib.HTTPMessage.readheaders() is based on mimetools.Message.\n\nI suggest to reuse parse_headers() in swift, maybe have a local on Python 2:\n\ntry:\n    from http.client import parse_headers\nexcept ImportError:\n    # python 2\n    def parse_headers(...):\n        ...\n\nCopy of the Python 3.6 code:\n\ndef parse_headers(fp, _class\u003dHTTPMessage):\n    \"\"\"Parses only RFC2822 headers from a file pointer.\n\n    email Parser wants to see strings rather than bytes.\n    But a TextIOWrapper around self.rfile would buffer too many bytes\n    from the stream, bytes which we later need to read as bytes.\n    So we read the correct bytes here, as bytes, for email Parser\n    to parse.\n\n    \"\"\"\n    headers \u003d []\n    while True:\n        line \u003d fp.readline(_MAXLINE + 1)\n        if len(line) \u003e _MAXLINE:\n            raise LineTooLong(\"header line\")\n        headers.append(line)\n        if len(headers) \u003e _MAXHEADERS:\n            raise HTTPException(\"got more than %d headers\" % _MAXHEADERS)\n        if line in (b\u0027\\r\\n\u0027, b\u0027\\n\u0027, b\u0027\u0027):\n            break\n    hstring \u003d b\u0027\u0027.join(headers).decode(\u0027iso-8859-1\u0027)\n    return email.parser.Parser(_class\u003d_class).parsestr(hstring)\n\n(I didn\u0027t try the code on Python 2.)","commit_id":"2c3850e92a2315d3b66c67500efa765488143a34"}]}
