This commit is contained in:
Maximilian Hils 2016-05-09 12:15:20 -06:00
parent 01f52ee56a
commit 9d47d3b1ec
3 changed files with 15 additions and 1 deletions

View File

@ -162,7 +162,7 @@ class Request(Message):
def path(self):
"""
HTTP request path, e.g. "/index.html".
Guaranteed to start with a slash.
Guaranteed to start with a slash, except for OPTIONS requests, which may just be "*".
"""
if self.data.path is None:
return None

View File

@ -330,6 +330,8 @@ def unparse_url(scheme, host, port, path=""):
Args:
All args must be str.
"""
if path == "*":
path = ""
return "%s://%s%s" % (scheme, hostport(scheme, host, port), path)

View File

@ -107,6 +107,14 @@ class TestRequestUtils(object):
with raises(ValueError):
request.url = "not-a-url"
def test_url_options(self):
request = treq(method="OPTIONS", path="*")
assert request.url == "http://address:22"
def test_url_authority(self):
request = treq(first_line_format="authority")
assert request.url == "address:22"
def test_pretty_host(self):
request = treq()
# Without host header
@ -140,6 +148,10 @@ class TestRequestUtils(object):
request.headers["host"] = "other"
assert request.pretty_url == "http://address:22/path"
def test_pretty_url_options(self):
request = treq(method="OPTIONS", path="*")
assert request.pretty_url == "http://address:22"
def test_pretty_url_authority(self):
request = treq(first_line_format="authority")
assert request.pretty_url == "address:22"