mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-02-01 07:49:10 +00:00
Merge pull request #192 from mitmproxy/refactor_read_http_body
move CONTINUE checks into mitmproxy
This commit is contained in:
commit
d5f9b02615
@ -424,8 +424,9 @@ class ProxyHandler(tcp.BaseHandler):
|
||||
raise ProxyError(400, "Bad HTTP request line: %s"%repr(line))
|
||||
method, scheme, host, port, path, httpversion = r
|
||||
headers = self.read_headers(authenticate=True)
|
||||
content = http.read_http_body_request(
|
||||
self.rfile, self.wfile, headers, httpversion, self.config.body_size_limit
|
||||
self.handle_expect_header(headers, httpversion)
|
||||
content = http.read_http_body(
|
||||
self.rfile, headers, self.config.body_size_limit, True
|
||||
)
|
||||
r = flow.Request(
|
||||
client_conn, httpversion, host, port, scheme, method, path, headers, content,
|
||||
@ -457,8 +458,9 @@ class ProxyHandler(tcp.BaseHandler):
|
||||
raise ProxyError(400, "Bad HTTP request line: %s"%repr(line))
|
||||
method, path, httpversion = r
|
||||
headers = self.read_headers(authenticate=False)
|
||||
content = http.read_http_body_request(
|
||||
self.rfile, self.wfile, headers, httpversion, self.config.body_size_limit
|
||||
self.handle_expect_header(headers, httpversion)
|
||||
content = http.read_http_body(
|
||||
self.rfile, headers, self.config.body_size_limit, True
|
||||
)
|
||||
r = flow.Request(
|
||||
client_conn, httpversion, host, port, scheme, method, path, headers, content,
|
||||
@ -467,6 +469,14 @@ class ProxyHandler(tcp.BaseHandler):
|
||||
r.set_live(self.rfile, self.wfile)
|
||||
return r
|
||||
|
||||
def handle_expect_header(self, headers, httpversion):
|
||||
if "expect" in headers:
|
||||
if "100-continue" in headers['expect'] and httpversion >= (1, 1):
|
||||
#FIXME: Check if content-length is over limit
|
||||
self.wfile.write('HTTP/1.1 100 Continue\r\n'
|
||||
'\r\n')
|
||||
del headers['expect']
|
||||
|
||||
def read_headers(self, authenticate=False):
|
||||
headers = http.read_headers(self.rfile)
|
||||
if headers is None:
|
||||
|
@ -176,10 +176,10 @@ class TestHTTPAuth(tservers.HTTPProxTest):
|
||||
class TestHTTPConnectSSLError(tservers.HTTPProxTest):
|
||||
certfile = True
|
||||
def test_go(self):
|
||||
p = self.pathoc()
|
||||
req = "connect:'localhost:%s'"%self.proxy.port
|
||||
assert p.request(req).status_code == 200
|
||||
assert p.request(req).status_code == 400
|
||||
p = self.pathoc_raw()
|
||||
dst = ("localhost", self.proxy.port)
|
||||
p.connect(connect_to=dst)
|
||||
tutils.raises("400 - Bad Request", p.http_connect, dst)
|
||||
|
||||
|
||||
class TestHTTPS(tservers.HTTPProxTest, CommonMixin):
|
||||
|
Loading…
Reference in New Issue
Block a user