aboutsummaryrefslogtreecommitdiffstats
path: root/libpathod/rparse.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-07-24 21:38:28 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-07-24 21:38:28 +1200
commit94b491bb277054af106f63e2e2b9cec6b9ca6d3c (patch)
treed77084ed160c7a3128d728d95fc9626bb9b64ce4 /libpathod/rparse.py
parent9502eeadaa8463019059137584a75597e20a5544 (diff)
downloadmitmproxy-94b491bb277054af106f63e2e2b9cec6b9ca6d3c.tar.gz
mitmproxy-94b491bb277054af106f63e2e2b9cec6b9ca6d3c.tar.bz2
mitmproxy-94b491bb277054af106f63e2e2b9cec6b9ca6d3c.zip
Add a Host header to pathoc requests by default.
Diffstat (limited to 'libpathod/rparse.py')
-rw-r--r--libpathod/rparse.py31
1 files changed, 20 insertions, 11 deletions
diff --git a/libpathod/rparse.py b/libpathod/rparse.py
index 767cb861..e56135ea 100644
--- a/libpathod/rparse.py
+++ b/libpathod/rparse.py
@@ -541,7 +541,7 @@ class Message:
l += len(i[2])
return l
- def serve(self, fp, check, is_request):
+ def serve(self, fp, check, request_host):
"""
fp: The file pointer to write to.
@@ -550,9 +550,11 @@ class Message:
otherwise the return is treated as an error message to be sent to
the client, and service stops.
- is_request: Is this a request? If False, we assume it's a response.
- Used to decide what standard modifications to make if raw is not
- set.
+ request_host: If this a request, this is the connecting host. If
+ None, we assume it's a response. Used to decide what standard
+ modifications to make if raw is not set.
+
+ Calling this function may modify the object.
"""
started = time.time()
if not self.raw:
@@ -563,8 +565,15 @@ class Message:
LiteralGenerator(str(len(self.body))),
)
)
- if is_request:
- pass
+ if request_host:
+ if not utils.get_header("Host", self.headers):
+ self.headers.append(
+ (
+ LiteralGenerator("Host"),
+ LiteralGenerator(request_host)
+ )
+ )
+
else:
if not utils.get_header("Date", self.headers):
self.headers.append(
@@ -706,8 +715,8 @@ class CraftedRequest(Request):
for i in tokens:
i.accept(settings, self)
- def serve(self, fp, check=None):
- d = Request.serve(self, fp, check, True)
+ def serve(self, fp, check, host):
+ d = Request.serve(self, fp, check, host)
d["spec"] = self.spec
return d
@@ -719,8 +728,8 @@ class CraftedResponse(Response):
for i in tokens:
i.accept(settings, self)
- def serve(self, fp, check=None):
- d = Response.serve(self, fp, check, False)
+ def serve(self, fp, check):
+ d = Response.serve(self, fp, check, None)
d["spec"] = self.spec
return d
@@ -738,7 +747,7 @@ class PathodErrorResponse(Response):
]
def serve(self, fp, check=None):
- d = Response.serve(self, fp, check, False)
+ d = Response.serve(self, fp, check, None)
d["internal"] = True
return d