aboutsummaryrefslogtreecommitdiffstats
path: root/test/http/http1
diff options
context:
space:
mode:
Diffstat (limited to 'test/http/http1')
-rw-r--r--test/http/http1/test_assemble.py6
-rw-r--r--test/http/http1/test_read.py22
2 files changed, 12 insertions, 16 deletions
diff --git a/test/http/http1/test_assemble.py b/test/http/http1/test_assemble.py
index 2d250909..963e7549 100644
--- a/test/http/http1/test_assemble.py
+++ b/test/http/http1/test_assemble.py
@@ -77,16 +77,16 @@ def test_assemble_request_line():
def test_assemble_request_headers():
# https://github.com/mitmproxy/mitmproxy/issues/186
r = treq(body=b"")
- r.headers[b"Transfer-Encoding"] = b"chunked"
+ r.headers["Transfer-Encoding"] = "chunked"
c = _assemble_request_headers(r)
assert b"Transfer-Encoding" in c
- assert b"Host" in _assemble_request_headers(treq(headers=Headers()))
+ assert b"host" in _assemble_request_headers(treq(headers=Headers()))
def test_assemble_response_headers():
# https://github.com/mitmproxy/mitmproxy/issues/186
r = tresp(body=b"")
- r.headers["Transfer-Encoding"] = b"chunked"
+ r.headers["Transfer-Encoding"] = "chunked"
c = _assemble_response_headers(r)
assert b"Transfer-Encoding" in c
diff --git a/test/http/http1/test_read.py b/test/http/http1/test_read.py
index 55def2a5..9eb02a24 100644
--- a/test/http/http1/test_read.py
+++ b/test/http/http1/test_read.py
@@ -1,9 +1,7 @@
from __future__ import absolute_import, print_function, division
from io import BytesIO
import textwrap
-
from mock import Mock
-
from netlib.exceptions import HttpException, HttpSyntaxException, HttpReadDisconnect
from netlib.http import Headers
from netlib.http.http1.read import (
@@ -35,7 +33,7 @@ def test_read_request_head():
rfile.first_byte_timestamp = 42
r = read_request_head(rfile)
assert r.method == b"GET"
- assert r.headers["Content-Length"] == b"4"
+ assert r.headers["Content-Length"] == "4"
assert r.body is None
assert rfile.reset_timestamps.called
assert r.timestamp_start == 42
@@ -62,7 +60,7 @@ def test_read_response_head():
rfile.first_byte_timestamp = 42
r = read_response_head(rfile)
assert r.status_code == 418
- assert r.headers["Content-Length"] == b"4"
+ assert r.headers["Content-Length"] == "4"
assert r.body is None
assert rfile.reset_timestamps.called
assert r.timestamp_start == 42
@@ -76,14 +74,12 @@ class TestReadBody(object):
assert body == b"foo"
assert rfile.read() == b"bar"
-
def test_known_size(self):
rfile = BytesIO(b"foobar")
body = b"".join(read_body(rfile, 3))
assert body == b"foo"
assert rfile.read() == b"bar"
-
def test_known_size_limit(self):
rfile = BytesIO(b"foobar")
with raises(HttpException):
@@ -99,7 +95,6 @@ class TestReadBody(object):
body = b"".join(read_body(rfile, -1))
assert body == b"foobar"
-
def test_unknown_size_limit(self):
rfile = BytesIO(b"foobar")
with raises(HttpException):
@@ -121,13 +116,13 @@ def test_connection_close():
def test_expected_http_body_size():
# Expect: 100-continue
assert expected_http_body_size(
- treq(headers=Headers(expect=b"100-continue", content_length=b"42"))
+ treq(headers=Headers(expect="100-continue", content_length="42"))
) == 0
# http://tools.ietf.org/html/rfc7230#section-3.3
assert expected_http_body_size(
treq(method=b"HEAD"),
- tresp(headers=Headers(content_length=b"42"))
+ tresp(headers=Headers(content_length="42"))
) == 0
assert expected_http_body_size(
treq(method=b"CONNECT"),
@@ -141,17 +136,17 @@ def test_expected_http_body_size():
# chunked
assert expected_http_body_size(
- treq(headers=Headers(transfer_encoding=b"chunked")),
+ treq(headers=Headers(transfer_encoding="chunked")),
) is None
# explicit length
- for l in (b"foo", b"-7"):
+ for val in (b"foo", b"-7"):
with raises(HttpSyntaxException):
expected_http_body_size(
- treq(headers=Headers(content_length=l))
+ treq(headers=Headers(content_length=val))
)
assert expected_http_body_size(
- treq(headers=Headers(content_length=b"42"))
+ treq(headers=Headers(content_length="42"))
) == 42
# no length
@@ -286,6 +281,7 @@ class TestReadHeaders(object):
with raises(HttpSyntaxException):
self._read(data)
+
def test_read_chunked():
req = treq(body=None)
req.headers["Transfer-Encoding"] = "chunked"