diff options
author | Maximilian Hils <git@maximilianhils.com> | 2015-09-16 18:45:22 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2015-09-16 18:45:22 +0200 |
commit | 0af060897854e0e0fc8207af02d22bec9eacab12 (patch) | |
tree | 8f5206386bb481a813f1b6891c30d5d2d33924ba /test/test_protocol_http.py | |
parent | 436a9ea8398e25709f139fde609aa74e8fb3f3f8 (diff) | |
download | mitmproxy-0af060897854e0e0fc8207af02d22bec9eacab12.tar.gz mitmproxy-0af060897854e0e0fc8207af02d22bec9eacab12.tar.bz2 mitmproxy-0af060897854e0e0fc8207af02d22bec9eacab12.zip |
adjust to netlib changes
Diffstat (limited to 'test/test_protocol_http.py')
-rw-r--r-- | test/test_protocol_http.py | 52 |
1 files changed, 21 insertions, 31 deletions
diff --git a/test/test_protocol_http.py b/test/test_protocol_http.py index f53d43cf..5ddb5b5b 100644 --- a/test/test_protocol_http.py +++ b/test/test_protocol_http.py @@ -1,46 +1,36 @@ -import cStringIO -from cStringIO import StringIO +from io import BytesIO +from netlib.exceptions import HttpSyntaxException -from mock import MagicMock - -from libmproxy.protocol.http import * -import netlib.http from netlib.http import http1 -from netlib.http.semantics import CONTENT_MISSING - +from netlib.tutils import treq, raises import tutils import tservers -def mock_protocol(data=''): - rfile = cStringIO.StringIO(data) - wfile = cStringIO.StringIO() - return http1.HTTP1Protocol(rfile=rfile, wfile=wfile) - class TestHTTPResponse: def test_read_from_stringio(self): - s = "HTTP/1.1 200 OK\r\n" \ - "Content-Length: 7\r\n" \ - "\r\n"\ - "content\r\n" \ - "HTTP/1.1 204 OK\r\n" \ - "\r\n" - - protocol = mock_protocol(s) - r = HTTPResponse.from_protocol(protocol, "GET") + s = ( + b"HTTP/1.1 200 OK\r\n" + b"Content-Length: 7\r\n" + b"\r\n" + b"content\r\n" + b"HTTP/1.1 204 OK\r\n" + b"\r\n" + ) + rfile = BytesIO(s) + r = http1.read_response(rfile, treq()) assert r.status_code == 200 - assert r.content == "content" - assert HTTPResponse.from_protocol(protocol, "GET").status_code == 204 + assert r.content == b"content" + assert http1.read_response(rfile, treq()).status_code == 204 - protocol = mock_protocol(s) + rfile = BytesIO(s) # HEAD must not have content by spec. We should leave it on the pipe. - r = HTTPResponse.from_protocol(protocol, "HEAD") + r = http1.read_response(rfile, treq(method=b"HEAD")) assert r.status_code == 200 - assert r.content == "" - tutils.raises( - "Invalid server response: 'content", - HTTPResponse.from_protocol, protocol, "GET" - ) + assert r.content == b"" + + with raises(HttpSyntaxException): + http1.read_response(rfile, treq()) class TestHTTPFlow(object): |