From 22120803fed3bffc61c85c1b1acef8c2d68e620e Mon Sep 17 00:00:00 2001 From: Shane Hathaway Date: Tue, 11 May 2021 08:42:05 -0600 Subject: Add REMOTE_URI to the WSGI environ. CHANGES.txt entry included. --- CHANGES.txt | 9 +++++++++ src/waitress/parser.py | 3 +++ src/waitress/task.py | 1 + tests/test_parser.py | 5 +++++ tests/test_task.py | 2 ++ 5 files changed, 20 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 8bd963f..d561c03 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,12 @@ +Next Release +------------ + +- Add REMOTE_URI to the WSGI environment. + + REMOTE_URI is similar to ``remote_uri`` in nginx. It is a string that + contains the request path before separating the query string and + decoding ``%``-escaped characters. + 2.0.0 (2021-03-07) ------------------ diff --git a/src/waitress/parser.py b/src/waitress/parser.py index 3b99921..a6e4d98 100644 --- a/src/waitress/parser.py +++ b/src/waitress/parser.py @@ -248,6 +248,9 @@ class HTTPRequestParser: # command, uri, version will be bytes command, uri, version = crack_first_line(first_line) + # self.request_uri is like nginx's request_uri: + # "full original request URI (with arguments)" + self.request_uri = uri.decode("latin-1") version = version.decode("latin-1") command = command.decode("latin-1") self.command = command diff --git a/src/waitress/task.py b/src/waitress/task.py index 2ac8f4c..a003919 100644 --- a/src/waitress/task.py +++ b/src/waitress/task.py @@ -538,6 +538,7 @@ class WSGITask(Task): "SERVER_PROTOCOL": "HTTP/%s" % self.version, "SCRIPT_NAME": url_prefix, "PATH_INFO": path, + "REQUEST_URI": request.request_uri, "QUERY_STRING": request.query, "wsgi.url_scheme": request.url_scheme, # the following environment variables are required by the WSGI spec diff --git a/tests/test_parser.py b/tests/test_parser.py index 0a68a66..aacef26 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -608,6 +608,11 @@ class TestHTTPRequestParserIntegration(unittest.TestCase): parser.path.encode("latin-1").decode("utf-8"), b"/foo/a++/\xc3\xa4=&a:int".decode("utf-8"), ) + # parser.request_uri should preserve the % escape sequences and the query string. + self.assertEqual( + parser.request_uri, + "/foo/a+%2B%2F%C3%A4%3D%26a%3Aint?d=b+%2B%2F%3D%26b%3Aint&c+%2B%2F%3D%26c%3Aint=6", + ) self.assertEqual( parser.query, "d=b+%2B%2F%3D%26b%3Aint&c+%2B%2F%3D%26c%3Aint=6" ) diff --git a/tests/test_task.py b/tests/test_task.py index ea71e02..cc579b0 100644 --- a/tests/test_task.py +++ b/tests/test_task.py @@ -797,6 +797,7 @@ class TestWSGITask(unittest.TestCase): "REMOTE_HOST", "REMOTE_PORT", "REQUEST_METHOD", + "REQUEST_URI", "SCRIPT_NAME", "SERVER_NAME", "SERVER_PORT", @@ -982,6 +983,7 @@ class DummyParser: version = "1.0" command = "GET" path = "/" + request_uri = "/" query = "" url_scheme = "http" expect_continue = False -- cgit v1.2.1