mirror of
https://github.com/mitmproxy/mitmproxy.git
synced 2024-12-04 19:46:44 +00:00
fix #313
This commit is contained in:
parent
2b31a9c49e
commit
c9be57b682
@ -930,9 +930,14 @@ class HTTPHandler(ProtocolHandler, TemporaryServerChangeMixin):
|
||||
|
||||
if (http.connection_close(flow.request.httpversion, flow.request.headers) or
|
||||
http.connection_close(flow.response.httpversion, flow.response.headers)):
|
||||
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,
|
||||
@ -1039,6 +1044,7 @@ class HTTPHandler(ProtocolHandler, TemporaryServerChangeMixin):
|
||||
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'
|
||||
)
|
||||
|
@ -54,7 +54,6 @@ class TestHTTPRequest:
|
||||
r = tutils.treq()
|
||||
tutils.raises("Invalid request form", r._assemble, "antiauthority")
|
||||
|
||||
|
||||
def test_set_url(self):
|
||||
r = tutils.treq_absolute()
|
||||
r.set_url("https://otheraddress:42/ORLY")
|
||||
@ -127,6 +126,21 @@ class TestProxyChainingSSL(tservers.HTTPChainProxyTest):
|
||||
# request from chain[1] to proxy
|
||||
assert self.proxy.tmaster.state.flow_count() == 1 # request from chain[0] (regular proxy doesn't store CONNECTs)
|
||||
|
||||
def test_closing_connect_response(self):
|
||||
"""
|
||||
https://github.com/mitmproxy/mitmproxy/issues/313
|
||||
"""
|
||||
def handle_request(r):
|
||||
r.httpversion = (1,0)
|
||||
del r.headers["Content-Length"]
|
||||
r.reply()
|
||||
_handle_request = self.chain[0].tmaster.handle_request
|
||||
self.chain[0].tmaster.handle_request = handle_request
|
||||
try:
|
||||
assert self.pathoc().request("get:/p/418").status_code == 418
|
||||
finally:
|
||||
self.chain[0].tmaster.handle_request = _handle_request
|
||||
|
||||
class TestProxyChainingSSLReconnect(tservers.HTTPChainProxyTest):
|
||||
ssl = True
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user