From 7c17c6ddbe12707795ea99b4f35df23cad576899 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sun, 14 Feb 2016 14:18:31 +0100 Subject: [PATCH 1/5] print http2 frames to debug log --- libmproxy/protocol/http2.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libmproxy/protocol/http2.py b/libmproxy/protocol/http2.py index 04ff8bf66..a65f76596 100644 --- a/libmproxy/protocol/http2.py +++ b/libmproxy/protocol/http2.py @@ -131,6 +131,12 @@ class Http2Layer(Layer): raise NotImplementedError() def _handle_event(self, event, source_conn, other_conn, is_server): + self.log( + "HTTP2 Event from {}".format("server" if is_server else "client"), + "debug", + [repr(event)] + ) + if hasattr(event, 'stream_id'): if is_server and event.stream_id % 2 == 1: eid = self.server_to_client_stream_ids[event.stream_id] From 5e65b933b291a4e53d27ce5671f776d828769f89 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Sun, 14 Feb 2016 14:36:44 +0100 Subject: [PATCH 2/5] improve landscape config --- .landscape.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.landscape.yml b/.landscape.yml index 9a3b615f7..9dfa62b0c 100644 --- a/.landscape.yml +++ b/.landscape.yml @@ -1,8 +1,12 @@ -max-line-length: 120 +ignore-paths: + - docs + - examples + - libmproxy/contrib + - web +max-line-length: 140 pylint: options: dummy-variables-rgx: _$|.+_$|dummy_.+ - disable: - missing-docstring - protected-access @@ -13,4 +17,4 @@ pylint: - too-many-public-methods - too-many-return-statements - too-many-statements - - unpacking-non-sequence \ No newline at end of file + - unpacking-non-sequence From efcfc62b73ac484ed25727f476c7ad0bb25817d5 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Sun, 14 Feb 2016 14:43:48 +0100 Subject: [PATCH 3/5] autopep8 --- libmproxy/console/__init__.py | 2 +- libmproxy/models/http.py | 1 - libmproxy/protocol/http2.py | 1 - libmproxy/stateobject.py | 1 + libmproxy/web/app.py | 1 + 5 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py index ad3f43060..e739ec61e 100644 --- a/libmproxy/console/__init__.py +++ b/libmproxy/console/__init__.py @@ -707,7 +707,7 @@ class ConsoleMaster(flow.FlowMaster): self.state.intercept) and not f.request.is_replay: f.intercept(self) else: - #check if flow was intercepted within an inline script by flow.intercept() + # check if flow was intercepted within an inline script by flow.intercept() if f.intercepted: f.intercept(self) else: diff --git a/libmproxy/models/http.py b/libmproxy/models/http.py index a2a345d70..3c22e4c93 100644 --- a/libmproxy/models/http.py +++ b/libmproxy/models/http.py @@ -13,7 +13,6 @@ from .. import version from .flow import Flow - class MessageMixin(object): def get_decoded_content(self): diff --git a/libmproxy/protocol/http2.py b/libmproxy/protocol/http2.py index a65f76596..895fc9a86 100644 --- a/libmproxy/protocol/http2.py +++ b/libmproxy/protocol/http2.py @@ -234,7 +234,6 @@ class Http2Layer(Layer): stream.zombie = time.time() return - frame, _ = hyperframe.frame.Frame.parse_frame_header(raw_frame[:9]) if is_server: diff --git a/libmproxy/stateobject.py b/libmproxy/stateobject.py index 9600ab091..a4a1ffda3 100644 --- a/libmproxy/stateobject.py +++ b/libmproxy/stateobject.py @@ -3,6 +3,7 @@ from netlib.utils import Serializable class StateObject(Serializable): + """ An object with serializable state. diff --git a/libmproxy/web/app.py b/libmproxy/web/app.py index 2c45a1dcc..4d940b5e7 100644 --- a/libmproxy/web/app.py +++ b/libmproxy/web/app.py @@ -42,6 +42,7 @@ class APIError(tornado.web.HTTPError): class BasicAuth(object): + def set_auth_headers(self): self.set_status(401) self.set_header('WWW-Authenticate', 'Basic realm=MITMWeb') From 6746cf5f546bedd0486edd23d5253759920e1448 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Sun, 14 Feb 2016 14:45:27 +0100 Subject: [PATCH 4/5] autoflake --- libmproxy/protocol/http.py | 1 - libmproxy/protocol/http1.py | 3 --- libmproxy/protocol/http2.py | 2 -- libmproxy/protocol/tls.py | 2 +- test/test_console_help.py | 2 +- test/test_filt.py | 4 ++-- test/test_flow.py | 4 ++-- test/test_protocol_http1.py | 3 +-- test/test_protocol_http2.py | 4 ---- 9 files changed, 7 insertions(+), 18 deletions(-) diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py index 4a86f9da6..13d7903bf 100644 --- a/libmproxy/protocol/http.py +++ b/libmproxy/protocol/http.py @@ -242,7 +242,6 @@ class HttpLayer(Layer): self.send_response(response) except (NetlibException, H2Error): self.log(traceback.format_exc(), "debug") - pass def change_upstream_proxy_server(self, address): # Make set_upstream_proxy_server always available, diff --git a/libmproxy/protocol/http1.py b/libmproxy/protocol/http1.py index fc2cf07a8..a4cd88014 100644 --- a/libmproxy/protocol/http1.py +++ b/libmproxy/protocol/http1.py @@ -1,12 +1,9 @@ from __future__ import (absolute_import, print_function, division) -import six -from netlib import tcp from netlib.http import http1 from .http import _HttpTransmissionLayer, HttpLayer -from .. import utils from ..models import HTTPRequest, HTTPResponse diff --git a/libmproxy/protocol/http2.py b/libmproxy/protocol/http2.py index 895fc9a86..c121637c5 100644 --- a/libmproxy/protocol/http2.py +++ b/libmproxy/protocol/http2.py @@ -18,8 +18,6 @@ from .base import Layer from .http import _HttpTransmissionLayer, HttpLayer from .. import utils from ..models import HTTPRequest, HTTPResponse -from ..exceptions import HttpProtocolException -from ..exceptions import ProtocolException class SafeH2Connection(H2Connection): diff --git a/libmproxy/protocol/tls.py b/libmproxy/protocol/tls.py index 986eb964e..378dd7d4a 100644 --- a/libmproxy/protocol/tls.py +++ b/libmproxy/protocol/tls.py @@ -419,7 +419,7 @@ class TlsLayer(Layer): try: self.ctx.connect() self._establish_tls_with_server() - except Exception as e: + except Exception: try: self._establish_tls_with_client() except: diff --git a/test/test_console_help.py b/test/test_console_help.py index 32d94247c..42862af76 100644 --- a/test/test_console_help.py +++ b/test/test_console_help.py @@ -28,7 +28,7 @@ class TestHelp: assert h.helptext() def test_keypress(self): - master = DummyMaster() + DummyMaster() h = help.HelpView([1, 2, 3]) assert not h.keypress((0, 0), "q") assert not h.keypress((0, 0), "?") diff --git a/test/test_filt.py b/test/test_filt.py index b1f3a21f8..498863716 100644 --- a/test/test_filt.py +++ b/test/test_filt.py @@ -209,7 +209,7 @@ class TestMatching: def test_method(self): q = self.req() - s = self.resp() + self.resp() assert self.q("~m get", q) assert not self.q("~m post", q) @@ -218,7 +218,7 @@ class TestMatching: def test_domain(self): q = self.req() - s = self.resp() + self.resp() assert self.q("~d host", q) assert not self.q("~d none", q) diff --git a/test/test_flow.py b/test/test_flow.py index 51b88fff8..fe2a45bff 100644 --- a/test/test_flow.py +++ b/test/test_flow.py @@ -350,7 +350,7 @@ class TestFlow(object): def test_copy(self): f = tutils.tflow(resp=True) - a0 = f.get_state() + f.get_state() f2 = f.copy() a = f.get_state() b = f2.get_state() @@ -532,7 +532,7 @@ class TestState: assert c.flow_count() == 2 assert c.active_flow_count() == 1 - _ = HTTPResponse.wrap(netlib.tutils.tresp()) + HTTPResponse.wrap(netlib.tutils.tresp()) assert not c.update_flow(None) assert c.active_flow_count() == 1 diff --git a/test/test_protocol_http1.py b/test/test_protocol_http1.py index a1485f1b4..13e0eabe7 100644 --- a/test/test_protocol_http1.py +++ b/test/test_protocol_http1.py @@ -1,7 +1,6 @@ -from netlib.exceptions import HttpSyntaxException from netlib.http import http1 from netlib.tcp import TCPClient -from netlib.tutils import treq, raises +from netlib.tutils import treq from . import tutils, tservers diff --git a/test/test_protocol_http2.py b/test/test_protocol_http2.py index 38cfdfc3c..c2c736af2 100644 --- a/test/test_protocol_http2.py +++ b/test/test_protocol_http2.py @@ -5,10 +5,8 @@ import pytest import traceback import os import tempfile -import sys from libmproxy.proxy.config import ProxyConfig -from libmproxy.proxy.server import ProxyServer from libmproxy.cmdline import APP_HOST, APP_PORT import logging @@ -24,9 +22,7 @@ from netlib import tservers as netlib_tservers from netlib.utils import http2_read_raw_frame import h2 -from hyperframe.frame import Frame -from libmproxy import utils from . import tservers requires_alpn = pytest.mark.skipif( From 4767474d4b867f5a85c7ea9ad5b8140a7bfa8b68 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Sun, 14 Feb 2016 14:58:36 +0100 Subject: [PATCH 5/5] remove noop code --- test/test_console_help.py | 16 ---------------- test/test_filt.py | 2 -- test/test_flow.py | 1 - 3 files changed, 19 deletions(-) diff --git a/test/test_console_help.py b/test/test_console_help.py index 42862af76..f1a71faf4 100644 --- a/test/test_console_help.py +++ b/test/test_console_help.py @@ -6,21 +6,6 @@ if os.name == "nt": import libmproxy.console.help as help -class DummyLoop: - - def __init__(self): - self.widget = None - - -class DummyMaster: - - def __init__(self): - self.loop = DummyLoop() - - def make_view(self): - pass - - class TestHelp: def test_helptext(self): @@ -28,7 +13,6 @@ class TestHelp: assert h.helptext() def test_keypress(self): - DummyMaster() h = help.HelpView([1, 2, 3]) assert not h.keypress((0, 0), "q") assert not h.keypress((0, 0), "?") diff --git a/test/test_filt.py b/test/test_filt.py index 498863716..e6873c7de 100644 --- a/test/test_filt.py +++ b/test/test_filt.py @@ -209,7 +209,6 @@ class TestMatching: def test_method(self): q = self.req() - self.resp() assert self.q("~m get", q) assert not self.q("~m post", q) @@ -218,7 +217,6 @@ class TestMatching: def test_domain(self): q = self.req() - self.resp() assert self.q("~d host", q) assert not self.q("~d none", q) diff --git a/test/test_flow.py b/test/test_flow.py index fe2a45bff..b122489fc 100644 --- a/test/test_flow.py +++ b/test/test_flow.py @@ -532,7 +532,6 @@ class TestState: assert c.flow_count() == 2 assert c.active_flow_count() == 1 - HTTPResponse.wrap(netlib.tutils.tresp()) assert not c.update_flow(None) assert c.active_flow_count() == 1