aboutsummaryrefslogtreecommitdiffstats
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
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.
-rw-r--r--netlib/http/http1/read.py14
-rw-r--r--netlib/utils.py12
-rw-r--r--test/netlib/http/http1/test_read.py13
-rw-r--r--test/netlib/test_utils.py11
4 files changed, 25 insertions, 25 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:
diff --git a/netlib/utils.py b/netlib/utils.py
index 91da471b..a2d8c97d 100644
--- a/netlib/utils.py
+++ b/netlib/utils.py
@@ -177,18 +177,6 @@ def is_valid_port(port):
return 0 <= port <= 65535
-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 hostport(scheme, host, port):
"""
Returns the host component, with a port specifcation if needed.
diff --git a/test/netlib/http/http1/test_read.py b/test/netlib/http/http1/test_read.py
index 974aa895..5285ac1d 100644
--- a/test/netlib/http/http1/test_read.py
+++ b/test/netlib/http/http1/test_read.py
@@ -7,11 +7,22 @@ from netlib.http.http1.read import (
read_request, read_response, read_request_head,
read_response_head, read_body, connection_close, expected_http_body_size, _get_first_line,
_read_request_line, _parse_authority_form, _read_response_line, _check_http_version,
- _read_headers, _read_chunked
+ _read_headers, _read_chunked, get_header_tokens
)
from netlib.tutils import treq, tresp, raises
+def test_get_header_tokens():
+ headers = Headers()
+ assert get_header_tokens(headers, "foo") == []
+ headers["foo"] = "bar"
+ assert get_header_tokens(headers, "foo") == ["bar"]
+ headers["foo"] = "bar, voing"
+ assert get_header_tokens(headers, "foo") == ["bar", "voing"]
+ headers.set_all("foo", ["bar, voing", "oink"])
+ assert get_header_tokens(headers, "foo") == ["bar", "voing", "oink"]
+
+
def test_read_request():
rfile = BytesIO(b"GET / HTTP/1.1\r\n\r\nskip")
r = read_request(rfile)
diff --git a/test/netlib/test_utils.py b/test/netlib/test_utils.py
index f9315667..c4ee3c10 100644
--- a/test/netlib/test_utils.py
+++ b/test/netlib/test_utils.py
@@ -38,17 +38,6 @@ def test_pretty_size():
assert utils.pretty_size(1024 * 1024) == "1MB"
-def test_get_header_tokens():
- headers = Headers()
- assert utils.get_header_tokens(headers, "foo") == []
- headers["foo"] = "bar"
- assert utils.get_header_tokens(headers, "foo") == ["bar"]
- headers["foo"] = "bar, voing"
- assert utils.get_header_tokens(headers, "foo") == ["bar", "voing"]
- headers.set_all("foo", ["bar, voing", "oink"])
- assert utils.get_header_tokens(headers, "foo") == ["bar", "voing", "oink"]
-
-
def test_multipartdecode():
boundary = 'somefancyboundary'
headers = Headers(