aboutsummaryrefslogtreecommitdiffstats
path: root/test/websockets/test_websockets.py
diff options
context:
space:
mode:
authorThomas Kriechbaumer <thomas@kriechbaumer.name>2015-07-16 22:56:34 +0200
committerThomas Kriechbaumer <thomas@kriechbaumer.name>2015-07-22 15:30:51 +0200
commit808b294865257fc3f52b33ed2a796009658b126f (patch)
treeebf522088ab56eda052bba7c78f298faa4306557 /test/websockets/test_websockets.py
parent230c16122b06f5c6af60e6ddc2d8e2e83cd75273 (diff)
downloadmitmproxy-808b294865257fc3f52b33ed2a796009658b126f.tar.gz
mitmproxy-808b294865257fc3f52b33ed2a796009658b126f.tar.bz2
mitmproxy-808b294865257fc3f52b33ed2a796009658b126f.zip
refactor HTTP/1 as protocol
Diffstat (limited to 'test/websockets/test_websockets.py')
-rw-r--r--test/websockets/test_websockets.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/test/websockets/test_websockets.py b/test/websockets/test_websockets.py
index 07ad0452..fb7ba39a 100644
--- a/test/websockets/test_websockets.py
+++ b/test/websockets/test_websockets.py
@@ -4,6 +4,7 @@ from nose.tools import raises
from netlib import tcp, http, websockets
from netlib.http.exceptions import *
+from netlib.http.http1 import HTTP1Protocol
from .. import tutils, tservers
@@ -32,10 +33,13 @@ class WebSocketsEchoHandler(tcp.BaseHandler):
frame.to_file(self.wfile)
def handshake(self):
- req = http.http1.read_request(self.rfile)
+ http1_protocol = HTTP1Protocol(self)
+
+ req = http1_protocol.read_request()
key = self.protocol.check_client_handshake(req.headers)
- self.wfile.write(http.http1.response_preamble(101) + "\r\n")
+ preamble = http1_protocol.response_preamble(101)
+ self.wfile.write(preamble + "\r\n")
headers = self.protocol.server_handshake_headers(key)
self.wfile.write(headers.format() + "\r\n")
self.wfile.flush()
@@ -56,14 +60,16 @@ class WebSocketsClient(tcp.TCPClient):
def connect(self):
super(WebSocketsClient, self).connect()
- preamble = http.http1.protocol.request_preamble("GET", "/")
+ http1_protocol = HTTP1Protocol(self)
+
+ preamble = http1_protocol.request_preamble("GET", "/")
self.wfile.write(preamble + "\r\n")
headers = self.protocol.client_handshake_headers()
self.client_nonce = headers.get_first("sec-websocket-key")
self.wfile.write(headers.format() + "\r\n")
self.wfile.flush()
- resp = http.http1.protocol.read_response(self.rfile, "get", None)
+ resp = http1_protocol.read_response("get", None)
server_nonce = self.protocol.check_server_handshake(resp.headers)
if not server_nonce == self.protocol.create_server_nonce(
@@ -151,10 +157,13 @@ class TestWebSockets(tservers.ServerTestBase):
class BadHandshakeHandler(WebSocketsEchoHandler):
def handshake(self):
- client_hs = http.http1.protocol.read_request(self.rfile)
+ http1_protocol = HTTP1Protocol(self)
+
+ client_hs = http1_protocol.read_request()
self.protocol.check_client_handshake(client_hs.headers)
- self.wfile.write(http.http1.protocol.response_preamble(101) + "\r\n")
+ preamble = http1_protocol.response_preamble(101)
+ self.wfile.write(preamble + "\r\n")
headers = self.protocol.server_handshake_headers("malformed key")
self.wfile.write(headers.format() + "\r\n")
self.wfile.flush()