From 0ebfea94a874bfedb522f413b7b14808be0e7345 Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Tue, 21 Jun 2016 08:20:06 -0700 Subject: [PATCH] Fix header name, add test --- README.rst | 6 +++--- daphne/http_protocol.py | 2 +- daphne/tests/test_http.py | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index b21eb8c..4ba1ca6 100644 --- a/README.rst +++ b/README.rst @@ -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:: diff --git a/daphne/http_protocol.py b/daphne/http_protocol.py index c69a3b5..db50591 100755 --- a/daphne/http_protocol.py +++ b/daphne/http_protocol.py @@ -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)) diff --git a/daphne/tests/test_http.py b/daphne/tests/test_http.py index d8b98c2..d0365a0 100644 --- a/daphne/tests/test_http.py +++ b/daphne/tests/test_http.py @@ -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")