diff options
-rw-r--r-- | netlib/http/request.py | 2 | ||||
-rw-r--r-- | netlib/utils.py | 2 | ||||
-rw-r--r-- | test/netlib/http/test_request.py | 12 |
3 files changed, 15 insertions, 1 deletions
diff --git a/netlib/http/request.py b/netlib/http/request.py index 6406a980..67aa17ce 100644 --- a/netlib/http/request.py +++ b/netlib/http/request.py @@ -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 diff --git a/netlib/utils.py b/netlib/utils.py index dda76808..ebd192f3 100644 --- a/netlib/utils.py +++ b/netlib/utils.py @@ -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) diff --git a/test/netlib/http/test_request.py b/test/netlib/http/test_request.py index 50ad2d05..91fd8ce3 100644 --- a/test/netlib/http/test_request.py +++ b/test/netlib/http/test_request.py @@ -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" |