move CONTINUE checks into mitmproxy

This commit is contained in:
Maximilian Hils 2013-12-15 06:33:18 +01:00
parent 6ec2e6f24f
commit f4b58ba495
2 changed files with 18 additions and 8 deletions

View File

@ -415,8 +415,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
)
return flow.Request(
client_conn, httpversion, host, port, scheme, method, path, headers, content,
@ -446,14 +447,23 @@ 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
)
return flow.Request(
client_conn, httpversion, host, port, scheme, method, path, headers, content,
self.rfile.first_byte_timestamp, utils.timestamp()
)
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:

View File

@ -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):