aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/proxy.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-05-16 15:42:58 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-05-16 15:42:58 +1200
commit0c2d894ceaefef6ae4b39c4f5a672a02672e4f8b (patch)
treed150a3029f7cf846973a38eaeb1b7739ebdfc056 /libmproxy/proxy.py
parent12b8a43dbe433adb2f713560ef6fd13b83bc13ee (diff)
downloadmitmproxy-0c2d894ceaefef6ae4b39c4f5a672a02672e4f8b.tar.gz
mitmproxy-0c2d894ceaefef6ae4b39c4f5a672a02672e4f8b.tar.bz2
mitmproxy-0c2d894ceaefef6ae4b39c4f5a672a02672e4f8b.zip
Add the ability to flag content as missing in a request or a response.
We'll use this in a number of situations. First, we'll soon have response streaming that directly pipes responses to clients. These will be content-less from mitmproxy's perspective. Second, we'll be growing new events that fire after headers are received, but before content is read.
Diffstat (limited to 'libmproxy/proxy.py')
-rw-r--r--libmproxy/proxy.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py
index 02ee8047..ffac6baa 100644
--- a/libmproxy/proxy.py
+++ b/libmproxy/proxy.py
@@ -250,7 +250,10 @@ class ServerConnection:
def send(self):
self.request.close = self.close
try:
- self.wfile.write(self.request._assemble())
+ d = self.request._assemble()
+ if not d:
+ raise ProxyError(502, "Incomplete request could not not be readied for transmission.")
+ self.wfile.write(d)
self.wfile.flush()
except socket.error, err:
raise ProxyError(502, 'Error sending data to "%s": %s' % (self.request.host, err))
@@ -448,7 +451,10 @@ class ProxyHandler(SocketServer.StreamRequestHandler):
return flow.Request(client_conn, host, port, scheme, method, path, headers, content)
def send_response(self, response):
- self.wfile.write(response._assemble())
+ d = response._assemble()
+ if not d:
+ raise ProxyError(502, "Incomplete response could not not be readied for transmission.")
+ self.wfile.write(d)
self.wfile.flush()
def terminate(self, connection, wfile, rfile):