aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/http/http1
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-05-31 18:54:42 +1200
committerAldo Cortesi <aldo@nullcube.com>2016-05-31 18:54:42 +1200
commit15b2374ef9d6a8cbafdff7c79694921387836ff3 (patch)
tree2c7ee11be9c114b23db6ae71183c6f82c2cb2bd8 /netlib/http/http1
parentda074bff01fbf359959eaa1e81b75db42e770b8b (diff)
downloadmitmproxy-15b2374ef9d6a8cbafdff7c79694921387836ff3.tar.gz
mitmproxy-15b2374ef9d6a8cbafdff7c79694921387836ff3.tar.bz2
mitmproxy-15b2374ef9d6a8cbafdff7c79694921387836ff3.zip
netlib.utils.get_header_tokens -> netlib.http1.read.get_header_tokens
Placing this next to its only use.
Diffstat (limited to 'netlib/http/http1')
-rw-r--r--netlib/http/http1/read.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/netlib/http/http1/read.py b/netlib/http/http1/read.py
index 93fca04e..5783ec67 100644
--- a/netlib/http/http1/read.py
+++ b/netlib/http/http1/read.py
@@ -9,6 +9,18 @@ from .. import Request, Response, Headers
from .. import url
+def get_header_tokens(headers, key):
+ """
+ Retrieve all tokens for a header key. A number of different headers
+ follow a pattern where each header line can containe comma-separated
+ tokens, and headers can be set multiple times.
+ """
+ if key not in headers:
+ return []
+ tokens = headers[key].split(",")
+ return [token.strip() for token in tokens]
+
+
def read_request(rfile, body_size_limit=None):
request = read_request_head(rfile)
expected_body_size = expected_http_body_size(request)
@@ -148,7 +160,7 @@ def connection_close(http_version, headers):
"""
# At first, check if we have an explicit Connection header.
if "connection" in headers:
- tokens = utils.get_header_tokens(headers, "connection")
+ tokens = get_header_tokens(headers, "connection")
if "close" in tokens:
return True
elif "keep-alive" in tokens: