aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/protocol
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2015-04-14 12:01:37 +1200
committerAldo Cortesi <aldo@nullcube.com>2015-04-14 12:01:37 +1200
commit937a358aa9396d5a5c18bc69e89e11af5dad40a5 (patch)
tree1d52a64527f93aeb5299d59e502ab792a052f7a2 /libmproxy/protocol
parentbea0bd236a60e3e6c80027448e51b7802394304a (diff)
parentcbf6cad8524b2b46a364898274871eba5dca776f (diff)
downloadmitmproxy-937a358aa9396d5a5c18bc69e89e11af5dad40a5.tar.gz
mitmproxy-937a358aa9396d5a5c18bc69e89e11af5dad40a5.tar.bz2
mitmproxy-937a358aa9396d5a5c18bc69e89e11af5dad40a5.zip
Merge branch 'master' of ssh.github.com:mitmproxy/mitmproxy
Diffstat (limited to 'libmproxy/protocol')
-rw-r--r--libmproxy/protocol/http.py33
1 files changed, 29 insertions, 4 deletions
diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py
index 496b71cc..94077e42 100644
--- a/libmproxy/protocol/http.py
+++ b/libmproxy/protocol/http.py
@@ -328,9 +328,22 @@ class HTTPRequest(HTTPMessage):
)
@classmethod
- def from_stream(cls, rfile, include_body=True, body_size_limit=None):
+ def from_stream(cls, rfile, include_body=True, body_size_limit=None, wfile=None):
"""
Parse an HTTP request from a file stream
+
+ Args:
+ rfile (file): Input file to read from
+ include_body (bool): Read response body as well
+ body_size_limit (bool): Maximum body size
+ wfile (file): If specified, HTTP Expect headers are handled automatically.
+ by writing a HTTP 100 CONTINUE response to the stream.
+
+ Returns:
+ HTTPRequest: The HTTP request
+
+ Raises:
+ HttpError: If the input is invalid.
"""
httpversion, host, port, scheme, method, path, headers, content, timestamp_start, timestamp_end = (
None, None, None, None, None, None, None, None, None, None)
@@ -385,6 +398,15 @@ class HTTPRequest(HTTPMessage):
if headers is None:
raise http.HttpError(400, "Invalid headers")
+ expect_header = headers.get_first("expect")
+ if expect_header and expect_header.lower() == "100-continue" and httpversion >= (1, 1):
+ wfile.write(
+ 'HTTP/1.1 100 Continue\r\n'
+ '\r\n'
+ )
+ wfile.flush()
+ del headers['expect']
+
if include_body:
content = http.read_http_body(rfile, headers, body_size_limit,
method, None, True)
@@ -609,8 +631,10 @@ class HTTPRequest(HTTPMessage):
host = self.headers.get_first("host")
if not host:
host = self.host
- host = host.encode("idna")
- return host
+ if host:
+ return host.encode("idna")
+ else:
+ return None
def pretty_url(self, hostheader):
if self.form_out == "authority": # upstream proxy mode
@@ -1062,7 +1086,8 @@ class HTTPHandler(ProtocolHandler):
try:
req = HTTPRequest.from_stream(
self.c.client_conn.rfile,
- body_size_limit=self.c.config.body_size_limit
+ body_size_limit=self.c.config.body_size_limit,
+ wfile=self.c.client_conn.wfile
)
except tcp.NetLibError:
# don't throw an error for disconnects that happen