diff --git a/netlib/h2/__init__.py b/netlib/http2/__init__.py similarity index 92% rename from netlib/h2/__init__.py rename to netlib/http2/__init__.py index c06f7a110..d6f2c51c0 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 similarity index 99% rename from netlib/h2/frame.py rename to netlib/http2/frame.py index 018e822f0..1497380a7 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 42a0c1cfe..d8a4febc7 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):