Fix header name, add test

This commit is contained in:
Andrew Godwin 2016-06-21 08:20:06 -07:00
parent cdafec588c
commit 0ebfea94a8
3 changed files with 19 additions and 4 deletions

View File

@ -30,11 +30,11 @@ Root Path (SCRIPT_NAME)
In order to set the root path for Daphne, which is the equivalent of the
WSGI ``SCRIPT_NAME`` setting, you have two options:
* Pass a header value ``DAPHNE_ROOT_PATH``, with the desired root path as a
URLencoded ASCII value
* Pass a header value ``Daphne-Root-Path``, with the desired root path as a
URLencoded ASCII value. This header will not be passed down to applications.
* Set the ``--root-path`` commandline option with the desired root path as a
URLencoded ASCII value
URLencoded ASCII value.
The header takes precedence if both are set. As with ``SCRIPT_ALIAS``, the value
should start with a slash, but not end with one; for example::

View File

@ -117,7 +117,7 @@ class WebRequest(http.Request):
if b"_" in name:
continue
for value in values:
if name.lower() == "daphne_root_path":
if name.lower() == "daphne-root-path":
self.root_path = self.unquote(value)
else:
self.clean_headers.append((name.lower(), value))

View File

@ -51,3 +51,18 @@ class TestHTTPProtocol(TestCase):
)
# Make sure that comes back right on the protocol
self.assertEqual(self.tr.value(), b"HTTP/1.1 201 Created\r\nTransfer-Encoding: chunked\r\nX-Test: Boom!\r\n\r\n6\r\nOH HAI\r\n0\r\n\r\n")
def test_root_path_header(self):
"""
Tests root path header handling
"""
# Send a simple request to the protocol
self.proto.dataReceived(
b"GET /te%20st-%C3%A0/?foo=bar HTTP/1.1\r\n" +
b"Host: somewhere.com\r\n" +
b"Daphne-Root-Path: /foobar%20/bar\r\n" +
b"\r\n"
)
# Get the resulting message off of the channel layer, check root_path
_, message = self.channel_layer.receive_many(["http.request"])
self.assertEqual(message['root_path'], "/foobar /bar")