From 3b0964f36555949d35659f306054876a49dbcfa1 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 30 Oct 2014 17:38:23 +0100 Subject: fix #391 --- libmproxy/proxy/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libmproxy/proxy/config.py b/libmproxy/proxy/config.py index fe2b45f4..a228192a 100644 --- a/libmproxy/proxy/config.py +++ b/libmproxy/proxy/config.py @@ -43,9 +43,9 @@ class ProxyConfig: self.body_size_limit = body_size_limit if mode == "transparent": - self.mode = TransparentProxyMode(platform.resolver(), TRANSPARENT_SSL_PORTS) + self.mode = TransparentProxyMode(platform.resolver(), ssl_ports) elif mode == "socks5": - self.mode = Socks5ProxyMode(TRANSPARENT_SSL_PORTS) + self.mode = Socks5ProxyMode(ssl_ports) elif mode == "reverse": self.mode = ReverseProxyMode(upstream_server) elif mode == "upstream": -- cgit v1.2.3 From 2c64b90a3d239c76bca4c334f89d7b53a965d35b Mon Sep 17 00:00:00 2001 From: Wade 524 Date: Fri, 31 Oct 2014 11:49:45 -0700 Subject: Adding some test coverage for handling HTTP OPTIONS requests. --- test/test_protocol_http.py | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/test/test_protocol_http.py b/test/test_protocol_http.py index ea6cf3fd..f5b9e0a1 100644 --- a/test/test_protocol_http.py +++ b/test/test_protocol_http.py @@ -23,7 +23,7 @@ def test_stripped_chunked_encoding_no_content(): class TestHTTPRequest: - def test_asterisk_form(self): + def test_asterisk_form_in(self): s = StringIO("OPTIONS * HTTP/1.1") f = tutils.tflow(req=None) f.request = HTTPRequest.from_stream(s) @@ -33,7 +33,7 @@ class TestHTTPRequest: f.request.scheme = "http" assert f.request.assemble() == "OPTIONS * HTTP/1.1\r\nHost: address:22\r\n\r\n" - def test_origin_form(self): + def test_relative_form_in(self): s = StringIO("GET /foo\xff HTTP/1.1") tutils.raises("Bad HTTP request line", HTTPRequest.from_stream, s) s = StringIO("GET /foo HTTP/1.1\r\nConnection: Upgrade\r\nUpgrade: h2c") @@ -52,8 +52,7 @@ class TestHTTPRequest: r.update_host_header() assert "Host" in r.headers - - def test_authority_form(self): + def test_authority_form_in(self): s = StringIO("CONNECT oops-no-port.com HTTP/1.1") tutils.raises("Bad HTTP request line", HTTPRequest.from_stream, s) s = StringIO("CONNECT address:22 HTTP/1.1") @@ -62,13 +61,37 @@ class TestHTTPRequest: assert r.assemble() == "CONNECT address:22 HTTP/1.1\r\nHost: address:22\r\n\r\n" assert r.pretty_url(False) == "address:22" - def test_absolute_form(self): + def test_absolute_form_in(self): s = StringIO("GET oops-no-protocol.com HTTP/1.1") tutils.raises("Bad HTTP request line", HTTPRequest.from_stream, s) s = StringIO("GET http://address:22/ HTTP/1.1") r = HTTPRequest.from_stream(s) assert r.assemble() == "GET http://address:22/ HTTP/1.1\r\nHost: address:22\r\n\r\n" + def test_http_options_relative_form_in(self): + """ + Exercises fix for Issue #xxx. + """ + s = StringIO("OPTIONS /secret/resource HTTP/1.1") + r = HTTPRequest.from_stream(s) + r.host = 'address' + r.port = 80 + r.scheme = "http" + assert r.assemble() == ("OPTIONS " + "/secret/resource " + "HTTP/1.1\r\nHost: address\r\n\r\n") + + def test_http_options_absolute_form_in(self): + s = StringIO("OPTIONS http://address/secret/resource HTTP/1.1") + r = HTTPRequest.from_stream(s) + r.host = 'address' + r.port = 80 + r.scheme = "http" + assert r.assemble() == ("OPTIONS " + "http://address:80/secret/resource " + "HTTP/1.1\r\nHost: address\r\n\r\n") + + def test_assemble_unknown_form(self): r = tutils.treq() tutils.raises("Invalid request form", r.assemble, "antiauthority") @@ -133,4 +156,4 @@ class TestInvalidRequests(tservers.HTTPProxTest): p.connect() r = p.request("get:/p/200") assert r.status_code == 400 - assert "Invalid HTTP request form" in r.content \ No newline at end of file + assert "Invalid HTTP request form" in r.content -- cgit v1.2.3 From ce18cd8ba40998c0654e697efcc0a0f018e45375 Mon Sep 17 00:00:00 2001 From: Wade 524 Date: Fri, 31 Oct 2014 11:50:03 -0700 Subject: Fixing issue #392. --- libmproxy/protocol/http.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py index 3560f0bd..1472f2ca 100644 --- a/libmproxy/protocol/http.py +++ b/libmproxy/protocol/http.py @@ -251,7 +251,7 @@ class HTTPRequest(HTTPMessage): - authority-form (CONNECT example.com:443) Details: http://tools.ietf.org/html/draft-ietf-httpbis-p1-messaging-25#section-5.3 - form_out: The request form which mitmproxy has send out to the + form_out: The request form which mitmproxy will send out to the destination timestamp_start: Timestamp indicating when request transmission started @@ -401,9 +401,8 @@ class HTTPRequest(HTTPMessage): form = form or self.form_out if form == "relative": - path = self.path if self.method != "OPTIONS" else "*" request_line = '%s %s HTTP/%s.%s' % ( - self.method, path, self.httpversion[0], self.httpversion[1] + self.method, self.path, self.httpversion[0], self.httpversion[1] ) elif form == "authority": request_line = '%s %s:%s HTTP/%s.%s' % ( -- cgit v1.2.3 From c4c42fa040f4e0177516e9830591ca36a3660f3f Mon Sep 17 00:00:00 2001 From: Wade 524 Date: Fri, 31 Oct 2014 12:45:31 -0700 Subject: Updating OPTIONS test with related issue number. --- test/test_protocol_http.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_protocol_http.py b/test/test_protocol_http.py index f5b9e0a1..db262950 100644 --- a/test/test_protocol_http.py +++ b/test/test_protocol_http.py @@ -70,7 +70,7 @@ class TestHTTPRequest: def test_http_options_relative_form_in(self): """ - Exercises fix for Issue #xxx. + Exercises fix for Issue #392. """ s = StringIO("OPTIONS /secret/resource HTTP/1.1") r = HTTPRequest.from_stream(s) -- cgit v1.2.3