Skip to content

Commit

Permalink
Merge pull request #16 from plehegar/plh/http/1.1-host-header
Browse files Browse the repository at this point in the history
Fixed Request.url to take the Host HTTP header into account with HTTP/1.1
  • Loading branch information
jgraham committed Apr 2, 2014
2 parents 5683a1e + d76b695 commit cfc6192
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions wptserve/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,17 +237,24 @@ def __init__(self, request_handler):
self.method = request_handler.command

scheme = request_handler.server.scheme
host = request_handler.server.server_address[0]
host = request_handler.headers.get("Host")
port = request_handler.server.server_address[1]

if host is None:
host = request_handler.server.server_address[0]
else:
if ":" in host:
host, port = host.split(":", 1)

self.request_path = request_handler.path

if self.request_path.startswith(scheme + "://"):
self.url = request_handler.path
else:
self.url = "%s://%s:%s%s" % (scheme,
host,
port,
self.request_path)
host,
port,
self.request_path)
self.url_parts = urlparse.urlsplit(self.url)

self._raw_headers = request_handler.headers
Expand Down

0 comments on commit cfc6192

Please sign in to comment.