aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/protocol/http.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2015-08-31 00:14:42 +0200
committerMaximilian Hils <git@maximilianhils.com>2015-08-31 00:14:42 +0200
commit1e9aef5b1e3e1d60a2bb94d47be03b780c10a497 (patch)
tree5ae39e8fcc183af470e25a77d10ca0bf7d0d349d /libmproxy/protocol/http.py
parent63ad4a4f5117d34ba6e9692eef1fc88f68b19c3d (diff)
downloadmitmproxy-1e9aef5b1e3e1d60a2bb94d47be03b780c10a497.tar.gz
mitmproxy-1e9aef5b1e3e1d60a2bb94d47be03b780c10a497.tar.bz2
mitmproxy-1e9aef5b1e3e1d60a2bb94d47be03b780c10a497.zip
fix upstream proxy server change, update example
Diffstat (limited to 'libmproxy/protocol/http.py')
-rw-r--r--libmproxy/protocol/http.py25
1 files changed, 12 insertions, 13 deletions
diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py
index 345b3aa8..3b62c389 100644
--- a/libmproxy/protocol/http.py
+++ b/libmproxy/protocol/http.py
@@ -207,6 +207,9 @@ class ConnectServerConnection(object):
def __getattr__(self, item):
return getattr(self.via, item)
+ def __nonzero__(self):
+ return bool(self.via)
+
class UpstreamConnectLayer(Layer):
def __init__(self, ctx, connect_request):
@@ -221,19 +224,22 @@ class UpstreamConnectLayer(Layer):
layer = self.ctx.next_layer(self)
layer()
+ def _send_connect_request(self):
+ self.send_request(self.connect_request)
+ resp = self.read_response("CONNECT")
+ if resp.code != 200:
+ raise ProtocolException("Reconnect: Upstream server refuses CONNECT request")
+
def connect(self):
if not self.server_conn:
self.ctx.connect()
- self.send_request(self.connect_request)
+ self._send_connect_request()
else:
pass # swallow the message
def reconnect(self):
self.ctx.reconnect()
- self.send_request(self.connect_request)
- resp = self.read_response("CONNECT")
- if resp.code != 200:
- raise ProtocolException("Reconnect: Upstream server refuses CONNECT request")
+ self._send_connect_request()
def set_server(self, address, server_tls=None, sni=None, depth=1):
if depth == 1:
@@ -386,7 +392,7 @@ class HttpLayer(Layer):
if self.supports_streaming:
flow.response = self.read_response_headers()
else:
- flow.response = self.read_response()
+ flow.response = self.read_response(flow.request.method)
try:
get_response()
@@ -473,13 +479,6 @@ class HttpLayer(Layer):
# Establish connection is neccessary.
if not self.server_conn:
self.connect()
-
- # SetServer is not guaranteed to work with TLS:
- # If there's not TlsLayer below which could catch the exception,
- # TLS will not be established.
- if tls and not self.server_conn.tls_established:
- raise ProtocolException(
- "Cannot upgrade to SSL, no TLS layer on the protocol stack.")
else:
if not self.server_conn:
self.connect()