From 62403a5bd8bf44b35f77d1e25a57bc0e12238b33 Mon Sep 17 00:00:00 2001 From: Ujjwal Verma Date: Mon, 19 Jun 2017 03:18:38 +0530 Subject: [PATCH 1/2] Fixes #2197 --- mitmproxy/master.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mitmproxy/master.py b/mitmproxy/master.py index b17f7e5dd..9e3550dae 100644 --- a/mitmproxy/master.py +++ b/mitmproxy/master.py @@ -162,6 +162,11 @@ class Master: f.response = None f.error = None + if f.request.http_version == "HTTP/2.0": + f.request.http_version = "HTTP/1.1" + host = f.request.headers.pop(":authority") + f.request.headers.insert(0, "host", host) + rt = http_replay.RequestReplayThread( self.server.config, f, From 08735ab0ae648c2060f83119443cb5d2e7288ec1 Mon Sep 17 00:00:00 2001 From: Ujjwal Verma Date: Mon, 26 Jun 2017 00:53:14 +0530 Subject: [PATCH 2/2] request replay test --- mitmproxy/master.py | 2 +- test/mitmproxy/test_flow.py | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/mitmproxy/master.py b/mitmproxy/master.py index 9e3550dae..2bc78f4b4 100644 --- a/mitmproxy/master.py +++ b/mitmproxy/master.py @@ -162,7 +162,7 @@ class Master: f.response = None f.error = None - if f.request.http_version == "HTTP/2.0": + if f.request.http_version == "HTTP/2.0": # https://github.com/mitmproxy/mitmproxy/issues/2197 f.request.http_version = "HTTP/1.1" host = f.request.headers.pop(":authority") f.request.headers.insert(0, "host", host) diff --git a/test/mitmproxy/test_flow.py b/test/mitmproxy/test_flow.py index 9f6ed585c..0b04c4c1b 100644 --- a/test/mitmproxy/test_flow.py +++ b/test/mitmproxy/test_flow.py @@ -1,7 +1,8 @@ import io +from unittest import mock import pytest -from mitmproxy.test import tflow +from mitmproxy.test import tflow, tutils import mitmproxy.io from mitmproxy import flowfilter from mitmproxy import options @@ -10,6 +11,7 @@ from mitmproxy.io import tnetstring from mitmproxy.exceptions import FlowReadException, ReplayException, ControlException from mitmproxy import flow from mitmproxy import http +from mitmproxy.net import http as net_http from mitmproxy.proxy.server import DummyServer from mitmproxy import master from . import tservers @@ -99,7 +101,9 @@ class TestFlowMaster: assert s.flows[0].request.host == "use-this-domain" def test_replay(self): - fm = master.Master(None, DummyServer()) + opts = options.Options() + conf = config.ProxyConfig(opts) + fm = master.Master(opts, DummyServer(conf)) f = tflow.tflow(resp=True) f.request.content = None with pytest.raises(ReplayException, match="missing"): @@ -117,6 +121,14 @@ class TestFlowMaster: with pytest.raises(ReplayException, match="live"): fm.replay_request(f) + req = tutils.treq(headers=net_http.Headers(((b":authority", b"foo"), (b"header", b"qvalue"), (b"content-length", b"7")))) + f = tflow.tflow(req=req) + f.request.http_version = "HTTP/2.0" + with mock.patch('mitmproxy.proxy.protocol.http_replay.RequestReplayThread.run'): + rt = fm.replay_request(f) + assert rt.f.request.http_version == "HTTP/1.1" + assert ":authority" not in rt.f.request.headers + def test_all(self): s = tservers.TestState() fm = master.Master(None, DummyServer())