aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libmproxy/console/__init__.py4
-rw-r--r--libmproxy/flow.py6
-rw-r--r--libmproxy/protocol/http.py20
-rw-r--r--test/test_protocol_http.py1
4 files changed, 16 insertions, 15 deletions
diff --git a/libmproxy/console/__init__.py b/libmproxy/console/__init__.py
index 24b3ddae..4f298698 100644
--- a/libmproxy/console/__init__.py
+++ b/libmproxy/console/__init__.py
@@ -568,13 +568,11 @@ class ConsoleMaster(flow.FlowMaster):
self.ui.set_terminal_properties(256)
self.ui.register_palette(self.palette)
self.flow_list_walker = flowlist.FlowListWalker(self, self.state)
-
self.view = None
self.statusbar = None
self.header = None
self.body = None
self.help_context = None
-
self.prompting = False
self.onekey = False
@@ -597,7 +595,6 @@ class ConsoleMaster(flow.FlowMaster):
print >> sys.stderr, traceback.format_exc()
print >> sys.stderr, "mitmproxy has crashed!"
print >> sys.stderr, "Please lodge a bug report at: https://github.com/mitmproxy/mitmproxy"
- # If True, quit just pops out to flow list view.
print >> sys.stderr, "Shutting down..."
sys.stderr.flush()
self.shutdown()
@@ -1028,7 +1025,6 @@ class ConsoleMaster(flow.FlowMaster):
e = urwid.Text(str(e))
elif level == "error":
e = urwid.Text(("error", str(e)))
-
self.eventlist.append(e)
if len(self.eventlist) > EVENTLOG_SIZE:
self.eventlist.pop(0)
diff --git a/libmproxy/flow.py b/libmproxy/flow.py
index 40786631..f4c24f28 100644
--- a/libmproxy/flow.py
+++ b/libmproxy/flow.py
@@ -5,7 +5,7 @@
import base64
import hashlib, Cookie, cookielib, re, threading
import os
-from flask import request
+import flask
import requests
import tnetstring, filt, script
from netlib import odict, wsgi
@@ -455,7 +455,7 @@ class FlowMaster(controller.Master):
else:
@app.mapp.before_request
def patch_environ(*args, **kwargs):
- request.environ["mitmproxy.master"] = self
+ flask.request.environ["mitmproxy.master"] = self
# the only absurd way to shut down a flask/werkzeug server.
# http://flask.pocoo.org/snippets/67/
@@ -464,7 +464,7 @@ class FlowMaster(controller.Master):
@app.mapp.route('/shutdown/<secret>')
def shutdown(secret):
if secret == shutdown_secret:
- request.environ.get('werkzeug.server.shutdown')()
+ flask.request.environ.get('werkzeug.server.shutdown')()
# Workaround: Monkey-patch shutdown function to stop the app.
# Improve this when we switch flask werkzeug for something useful.
diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py
index 06465fc4..e91e865a 100644
--- a/libmproxy/protocol/http.py
+++ b/libmproxy/protocol/http.py
@@ -877,11 +877,17 @@ class HTTPHandler(ProtocolHandler, TemporaryServerChangeMixin):
def handle_flow(self):
flow = HTTPFlow(self.c.client_conn, self.c.server_conn, self.change_server)
try:
- flow.request = HTTPRequest.from_stream(self.c.client_conn.rfile,
+ req = HTTPRequest.from_stream(self.c.client_conn.rfile,
body_size_limit=self.c.config.body_size_limit)
- self.c.log("request", [flow.request._assemble_first_line(flow.request.form_in)])
- self.process_request(flow.request)
-
+ self.c.log("request", [req._assemble_first_line(req.form_in)])
+ self.process_request(flow, req)
+
+ # Be careful NOT to assign the request to the flow before
+ # process_request completes. This is because the call can raise an
+ # exception. If the requets object is already attached, this results
+ # in an Error object that has an attached request that has not been
+ # sent through to the Master.
+ flow.request = req
request_reply = self.c.channel.ask("request", flow.request)
flow.server_conn = self.c.server_conn
@@ -1004,7 +1010,7 @@ class HTTPHandler(ProtocolHandler, TemporaryServerChangeMixin):
self.c.log("Upgrade to SSL completed.")
raise ConnectionTypeChange
- def process_request(self, request):
+ def process_request(self, flow, request):
if self.c.mode == "regular":
self.authenticate(request)
if request.form_in == "authority" and self.c.client_conn.ssl_established:
@@ -1015,7 +1021,7 @@ class HTTPHandler(ProtocolHandler, TemporaryServerChangeMixin):
directly_addressed_at_mitmproxy = (self.c.mode == "regular" and not self.c.config.forward_proxy)
if directly_addressed_at_mitmproxy:
self.c.set_server_address((request.host, request.port), AddressPriority.FROM_PROTOCOL)
- request.flow.server_conn = self.c.server_conn # Update server_conn attribute on the flow
+ flow.server_conn = self.c.server_conn # Update server_conn attribute on the flow
self.c.client_conn.wfile.write(
'HTTP/1.1 200 Connection established\r\n' +
('Proxy-agent: %s\r\n' % self.c.server_version) +
@@ -1033,7 +1039,7 @@ class HTTPHandler(ProtocolHandler, TemporaryServerChangeMixin):
if not self.c.config.forward_proxy:
request.form_out = "origin"
self.c.set_server_address((request.host, request.port), AddressPriority.FROM_PROTOCOL)
- request.flow.server_conn = self.c.server_conn # Update server_conn attribute on the flow
+ flow.server_conn = self.c.server_conn # Update server_conn attribute on the flow
else:
raise http.HttpError(400, "Invalid request form (absolute-form or authority-form required)")
diff --git a/test/test_protocol_http.py b/test/test_protocol_http.py
index 3bf5af22..d2ba24de 100644
--- a/test/test_protocol_http.py
+++ b/test/test_protocol_http.py
@@ -44,7 +44,6 @@ class TestHTTPRequest:
r = HTTPRequest.from_stream(s)
assert r._assemble() == "CONNECT address:22 HTTP/1.1\r\nHost: address:22\r\n\r\n"
-
def test_absolute_form(self):
s = StringIO("GET oops-no-protocol.com HTTP/1.1")
tutils.raises("Bad HTTP request line", HTTPRequest.from_stream, s)