aboutsummaryrefslogtreecommitdiffstats
path: root/mitmproxy/proxy
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2018-04-05 15:30:04 +0200
committerMaximilian Hils <git@maximilianhils.com>2018-04-05 15:30:04 +0200
commit50ea3aa420588d67acc17022a9824e819d22c4b1 (patch)
tree3cc73a8416db46d8a962c3f021e2b80471d140a5 /mitmproxy/proxy
parent8e54a365fa9617f3037946538044a9905b422952 (diff)
downloadmitmproxy-50ea3aa420588d67acc17022a9824e819d22c4b1.tar.gz
mitmproxy-50ea3aa420588d67acc17022a9824e819d22c4b1.tar.bz2
mitmproxy-50ea3aa420588d67acc17022a9824e819d22c4b1.zip
fix http retry timeout
this fixes #3038
Diffstat (limited to 'mitmproxy/proxy')
-rw-r--r--mitmproxy/proxy/protocol/http.py35
1 files changed, 21 insertions, 14 deletions
diff --git a/mitmproxy/proxy/protocol/http.py b/mitmproxy/proxy/protocol/http.py
index 99286fa5..24b411e8 100644
--- a/mitmproxy/proxy/protocol/http.py
+++ b/mitmproxy/proxy/protocol/http.py
@@ -333,8 +333,20 @@ class HttpLayer(base.Layer):
f.request.scheme
)
- try:
+ def get_response():
self.send_request_headers(f.request)
+ if f.request.stream:
+ chunks = self.read_request_body(f.request)
+ if callable(f.request.stream):
+ chunks = f.request.stream(chunks)
+ self.send_request_body(f.request, chunks)
+ else:
+ self.send_request_body(f.request, [f.request.data.content])
+
+ f.response = self.read_response_headers()
+
+ try:
+ get_response()
except exceptions.NetlibException as e:
self.log(
"server communication error: %s" % repr(e),
@@ -357,22 +369,17 @@ class HttpLayer(base.Layer):
raise exceptions.ProtocolException(
"First and only attempt to get response via HTTP2 failed."
)
+ elif f.request.stream:
+ # We may have already consumed some request chunks already,
+ # so all we can do is signal downstream that upstream closed the connection.
+ self.send_error_response(408, "Request Timeout")
+ f.error = flow.Error(repr(e))
+ self.channel.ask("error", f)
+ return False
self.disconnect()
self.connect()
- self.send_request_headers(f.request)
-
- # This is taken out of the try except block because when streaming
- # we can't send the request body while retrying as the generator gets exhausted
- if f.request.stream:
- chunks = self.read_request_body(f.request)
- if callable(f.request.stream):
- chunks = f.request.stream(chunks)
- self.send_request_body(f.request, chunks)
- else:
- self.send_request_body(f.request, [f.request.data.content])
-
- f.response = self.read_response_headers()
+ get_response()
# call the appropriate script hook - this is an opportunity for
# an inline script to set f.stream = True