aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Kriechbaumer <thomas@kriechbaumer.name>2015-06-04 19:44:48 +0200
committerThomas Kriechbaumer <thomas@kriechbaumer.name>2015-06-05 13:33:37 +0200
commitf003f87197a6dffe1b51a82f7dd218121c75e206 (patch)
tree9d1a19022cbe58bdedddd267d312f57e33905796
parent623dd850e0ce15630e0950b4de843c0af8046618 (diff)
downloadmitmproxy-f003f87197a6dffe1b51a82f7dd218121c75e206.tar.gz
mitmproxy-f003f87197a6dffe1b51a82f7dd218121c75e206.tar.bz2
mitmproxy-f003f87197a6dffe1b51a82f7dd218121c75e206.zip
http2: rename module and refactor as strategy
-rw-r--r--netlib/http2/__init__.py (renamed from netlib/h2/__init__.py)17
-rw-r--r--netlib/http2/frame.py (renamed from netlib/h2/frame.py)2
-rw-r--r--test/h2/test_frames.py2
3 files changed, 13 insertions, 8 deletions
diff --git a/netlib/h2/__init__.py b/netlib/http2/__init__.py
index c06f7a11..d6f2c51c 100644
--- a/netlib/h2/__init__.py
+++ b/netlib/http2/__init__.py
@@ -41,24 +41,27 @@ class HTTP2Protocol(object):
SettingsFrame.SETTINGS.SETTINGS_MAX_HEADER_LIST_SIZE: None,
}
- def __init__(self):
+ def __init__(self, tcp_client):
+ self.tcp_client = tcp_client
+
self.http2_settings = self.HTTP2_DEFAULT_SETTINGS.copy()
self.current_stream_id = None
self.encoder = Encoder()
self.decoder = Decoder()
def check_alpn(self):
- alp = self.get_alpn_proto_negotiated()
+ alp = self.tcp_client.get_alpn_proto_negotiated()
if alp != self.ALPN_PROTO_H2:
raise NotImplementedError(
"H2Client can not handle unknown ALP: %s" % alp)
log.debug("ALP 'h2' successfully negotiated.")
def send_connection_preface(self):
- self.wfile.write(bytes(self.CLIENT_CONNECTION_PREFACE.decode('hex')))
+ self.tcp_client.wfile.write(
+ bytes(self.CLIENT_CONNECTION_PREFACE.decode('hex')))
self.send_frame(SettingsFrame(state=self))
- frame = Frame.from_file(self.rfile, self)
+ frame = Frame.from_file(self.tcp_client.rfile, self)
assert isinstance(frame, SettingsFrame)
self._apply_settings(frame.settings)
self.read_frame() # read setting ACK frame
@@ -74,11 +77,11 @@ class HTTP2Protocol(object):
def send_frame(self, frame):
raw_bytes = frame.to_bytes()
- self.wfile.write(raw_bytes)
- self.wfile.flush()
+ self.tcp_client.wfile.write(raw_bytes)
+ self.tcp_client.wfile.flush()
def read_frame(self):
- frame = Frame.from_file(self.rfile, self)
+ frame = Frame.from_file(self.tcp_client.rfile, self)
if isinstance(frame, SettingsFrame):
self._apply_settings(frame.settings)
diff --git a/netlib/h2/frame.py b/netlib/http2/frame.py
index 018e822f..1497380a 100644
--- a/netlib/h2/frame.py
+++ b/netlib/http2/frame.py
@@ -7,9 +7,11 @@ from .. import utils
log = logging.getLogger(__name__)
+
class FrameSizeError(Exception):
pass
+
class Frame(object):
"""
diff --git a/test/h2/test_frames.py b/test/h2/test_frames.py
index 42a0c1cf..d8a4febc 100644
--- a/test/h2/test_frames.py
+++ b/test/h2/test_frames.py
@@ -1,6 +1,6 @@
import tutils
from nose.tools import assert_equal
-from netlib.h2.frame import *
+from netlib.http2.frame import *
class FileAdapter(object):