diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2015-04-21 11:11:16 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2015-04-21 11:11:16 +1200 |
commit | dd7ea896f24514bb2534b3762255e99f0aabc055 (patch) | |
tree | 4d1fec09dd03336b8b85040ebf90e437069f4d34 /netlib/http.py | |
parent | 2c660d76337b11eb438a2978ec3bda3ac10babd5 (diff) | |
download | mitmproxy-dd7ea896f24514bb2534b3762255e99f0aabc055.tar.gz mitmproxy-dd7ea896f24514bb2534b3762255e99f0aabc055.tar.bz2 mitmproxy-dd7ea896f24514bb2534b3762255e99f0aabc055.zip |
Return a named tuple from read_response
Diffstat (limited to 'netlib/http.py')
-rw-r--r-- | netlib/http.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/netlib/http.py b/netlib/http.py index aacdd1d4..5501ce73 100644 --- a/netlib/http.py +++ b/netlib/http.py @@ -314,6 +314,18 @@ def parse_response_line(line): return (proto, code, msg) +Response = collections.namedtuple( + "Response", + [ + "httpversion", + "code", + "msg", + "headers", + "content" + ] +) + + def read_response(rfile, request_method, body_size_limit, include_body=True): """ Return an (httpversion, code, msg, headers, content) tuple. @@ -352,7 +364,7 @@ def read_response(rfile, request_method, body_size_limit, include_body=True): # if include_body==False then a None content means the body should be # read separately content = None - return httpversion, code, msg, headers, content + return Response(httpversion, code, msg, headers, content) def read_http_body(*args, **kwargs): @@ -531,8 +543,8 @@ def read_request(rfile, include_body=True, body_size_limit=None, wfile=None): if headers is None: raise HttpError(400, "Invalid headers") - expect_header = headers.get_first("expect") - if expect_header and expect_header.lower() == "100-continue" and httpversion >= (1, 1): + expect_header = headers.get_first("expect", "").lower() + if expect_header == "100-continue" and httpversion >= (1, 1): wfile.write( 'HTTP/1.1 100 Continue\r\n' '\r\n' |