aboutsummaryrefslogtreecommitdiffstats
path: root/netlib
diff options
context:
space:
mode:
authorThomas Kriechbaumer <thomas@kriechbaumer.name>2015-06-15 17:31:08 +0200
committerThomas Kriechbaumer <thomas@kriechbaumer.name>2015-06-16 15:00:28 +0200
commitabb37a3ef52ab9a0f68dc46e4a8ca165e365139b (patch)
treeff569a1321eb3cef327d9e5f5843840a577eaeb1 /netlib
parent20c136e070cee0e93e870bf32199cb36b1b85275 (diff)
downloadmitmproxy-abb37a3ef52ab9a0f68dc46e4a8ca165e365139b.tar.gz
mitmproxy-abb37a3ef52ab9a0f68dc46e4a8ca165e365139b.tar.bz2
mitmproxy-abb37a3ef52ab9a0f68dc46e4a8ca165e365139b.zip
http2: improve test suite
Diffstat (limited to 'netlib')
-rw-r--r--netlib/http2/protocol.py16
-rw-r--r--netlib/tcp.py9
2 files changed, 13 insertions, 12 deletions
diff --git a/netlib/http2/protocol.py b/netlib/http2/protocol.py
index a77edd9b..8191090c 100644
--- a/netlib/http2/protocol.py
+++ b/netlib/http2/protocol.py
@@ -55,7 +55,7 @@ class HTTP2Protocol(object):
if isinstance(frm, frame.SettingsFrame):
break
- def _read_settings_ack(self, hide=False):
+ def _read_settings_ack(self, hide=False): # pragma no cover
while True:
frm = self.read_frame(hide)
if isinstance(frm, frame.SettingsFrame):
@@ -99,12 +99,12 @@ class HTTP2Protocol(object):
raw_bytes = frm.to_bytes()
self.tcp_handler.wfile.write(raw_bytes)
self.tcp_handler.wfile.flush()
- if not hide and self.dump_frames:
+ if not hide and self.dump_frames: # pragma no cover
print(frm.human_readable(">>"))
def read_frame(self, hide=False):
frm = frame.Frame.from_file(self.tcp_handler.rfile, self)
- if not hide and self.dump_frames:
+ if not hide and self.dump_frames: # pragma no cover
print(frm.human_readable("<<"))
if isinstance(frm, frame.SettingsFrame) and not frm.flags & frame.Frame.FLAG_ACK:
self._apply_settings(frm.settings, hide)
@@ -123,7 +123,9 @@ class HTTP2Protocol(object):
state=self,
flags=frame.Frame.FLAG_ACK),
hide)
- # self._read_settings_ack(hide)
+
+ # be liberal in what we expect from the other end
+ # to be more strict use: self._read_settings_ack(hide)
def _create_headers(self, headers, stream_id, end_stream=True):
# TODO: implement max frame size checks and sending in chunks
@@ -140,7 +142,7 @@ class HTTP2Protocol(object):
stream_id=stream_id,
header_block_fragment=header_block_fragment)
- if self.dump_frames:
+ if self.dump_frames: # pragma no cover
print(frm.human_readable(">>"))
return [frm.to_bytes()]
@@ -158,7 +160,7 @@ class HTTP2Protocol(object):
stream_id=stream_id,
payload=body)
- if self.dump_frames:
+ if self.dump_frames: # pragma no cover
print(frm.human_readable(">>"))
return [frm.to_bytes()]
@@ -225,8 +227,6 @@ class HTTP2Protocol(object):
if headers is None:
headers = []
- body='foobar'
-
headers = [(b':status', bytes(str(code)))] + headers
if not stream_id:
diff --git a/netlib/tcp.py b/netlib/tcp.py
index 2e847d83..cafc3ed9 100644
--- a/netlib/tcp.py
+++ b/netlib/tcp.py
@@ -414,6 +414,9 @@ class _Connection(object):
if cipher_list:
try:
context.set_cipher_list(cipher_list)
+
+ # TODO: maybe change this to with newer pyOpenSSL APIs
+ context.set_tmp_ecdh(OpenSSL.crypto.get_elliptic_curve('prime256v1'))
except SSL.Error as v:
raise NetLibError("SSL cipher specification error: %s" % str(v))
@@ -421,8 +424,6 @@ class _Connection(object):
if log_ssl_key:
context.set_info_callback(log_ssl_key)
- context.set_tmp_ecdh(OpenSSL.crypto.get_elliptic_curve('prime256v1'))
-
if OpenSSL._util.lib.Cryptography_HAS_ALPN:
if alpn_protos is not None:
# advertise application layer protocols
@@ -526,7 +527,7 @@ class TCPClient(_Connection):
if OpenSSL._util.lib.Cryptography_HAS_ALPN and self.ssl_established:
return self.connection.get_alpn_proto_negotiated()
else:
- return None
+ return ""
class BaseHandler(_Connection):
@@ -636,7 +637,7 @@ class BaseHandler(_Connection):
if OpenSSL._util.lib.Cryptography_HAS_ALPN and self.ssl_established:
return self.connection.get_alpn_proto_negotiated()
else:
- return None
+ return ""
class TCPServer(object):