diff options
Diffstat (limited to 'libmproxy/protocol/http.py')
-rw-r--r-- | libmproxy/protocol/http.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py index cc6533b2..6837327b 100644 --- a/libmproxy/protocol/http.py +++ b/libmproxy/protocol/http.py @@ -751,7 +751,7 @@ class HTTPFlow(Flow): """ def __init__(self, client_conn, server_conn, change_server=None): - Flow.__init__(self, "http", client_conn, server_conn) + super(HTTPFlow, self).__init__("http", client_conn, server_conn) self.request = None """@type: HTTPRequest""" self.response = None @@ -963,9 +963,14 @@ class HTTPHandler(ProtocolHandler, TemporaryServerChangeMixin): http.connection_close(flow.response.httpversion, flow.response.headers) or http.expected_http_body_size(flow.response.headers, False, flow.request.method, flow.response.code) == -1): - return False + if flow.request.form_in == "authority" and flow.response.code == 200: + # Workaround for https://github.com/mitmproxy/mitmproxy/issues/313: + # Some proxies (e.g. Charles) send a CONNECT response with HTTP/1.0 and no Content-Length header + pass + else: + return False - if flow.request.form_in == "authority": + if flow.request.form_in == "authority" and flow.response.code == 200: self.ssl_upgrade() # If the user has changed the target server on this connection, @@ -1069,12 +1074,15 @@ class HTTPHandler(ProtocolHandler, TemporaryServerChangeMixin): if not self.c.config.get_upstream_server: self.c.set_server_address((request.host, request.port), proxy.AddressPriority.FROM_PROTOCOL) + self.c.establish_server_connection() flow.server_conn = self.c.server_conn # Update server_conn attribute on the flow self.c.client_conn.send( 'HTTP/1.1 200 Connection established\r\n' + + 'Content-Length: 0\r\n' + ('Proxy-agent: %s\r\n' % self.c.server_version) + '\r\n' ) + self.ssl_upgrade() self.skip_authentication = True return False |