mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
add content-length 0 if we remove header for chunked encoding, fixes #186
This commit is contained in:
parent
4a32a65e0e
commit
39ffe10334
@ -735,6 +735,8 @@ class Response(HTTPMsg):
|
|||||||
)
|
)
|
||||||
if self.content:
|
if self.content:
|
||||||
headers["Content-Length"] = [str(len(self.content))]
|
headers["Content-Length"] = [str(len(self.content))]
|
||||||
|
elif 'Transfer-Encoding' in self.headers:
|
||||||
|
headers["Content-Length"] = ["0"]
|
||||||
proto = "HTTP/%s.%s %s %s"%(self.httpversion[0], self.httpversion[1], self.code, str(self.msg))
|
proto = "HTTP/%s.%s %s %s"%(self.httpversion[0], self.httpversion[1], self.code, str(self.msg))
|
||||||
data = (proto, str(headers))
|
data = (proto, str(headers))
|
||||||
return FMT%data
|
return FMT%data
|
||||||
|
@ -143,7 +143,18 @@ class TestHTTP(tservers.HTTPProxTest, CommonMixin, AppMixin):
|
|||||||
req = p.request("get:'http://foo':h':foo'='bar'")
|
req = p.request("get:'http://foo':h':foo'='bar'")
|
||||||
assert req.status_code == 400
|
assert req.status_code == 400
|
||||||
|
|
||||||
|
def test_empty_chunked_content(self):
|
||||||
|
"""
|
||||||
|
https://github.com/mitmproxy/mitmproxy/issues/186
|
||||||
|
"""
|
||||||
|
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
connection.connect(("127.0.0.1", self.proxy.port))
|
||||||
|
spec = '301:h"Transfer-Encoding"="chunked":r:b"0\\r\\n\\r\\n"'
|
||||||
|
connection.send("GET http://localhost:%d/p/%s HTTP/1.1\r\n"%(self.server.port, spec))
|
||||||
|
connection.send("\r\n");
|
||||||
|
resp = connection.recv(50000)
|
||||||
|
connection.close()
|
||||||
|
assert "content-length" in resp.lower()
|
||||||
|
|
||||||
class TestHTTPAuth(tservers.HTTPProxTest):
|
class TestHTTPAuth(tservers.HTTPProxTest):
|
||||||
authenticator = http_auth.BasicProxyAuth(http_auth.PassManSingleUser("test", "test"), "realm")
|
authenticator = http_auth.BasicProxyAuth(http_auth.PassManSingleUser("test", "test"), "realm")
|
||||||
|
Loading…
Reference in New Issue
Block a user