Skip to content

Commit

Permalink
Merge pull request mitmproxy#192 from mitmproxy/refactor_read_http_body
Browse files Browse the repository at this point in the history
move CONTINUE checks into mitmproxy
  • Loading branch information
cortesi committed Jan 4, 2014
2 parents 7d37e0c + f4b58ba commit d5f9b02
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
18 changes: 14 additions & 4 deletions libmproxy/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,9 @@ def _read_request_absolute_form(self, client_conn, line):
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,
Expand Down Expand Up @@ -457,8 +458,9 @@ def _read_request_origin_form(self, client_conn, scheme, host, port):
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,
Expand All @@ -467,6 +469,14 @@ def _read_request_origin_form(self, client_conn, scheme, host, port):
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:
Expand Down
8 changes: 4 additions & 4 deletions test/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ def test_auth(self):
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):
Expand Down

0 comments on commit d5f9b02

Please sign in to comment.