summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShane Hathaway <shane@willowrise.com>2021-05-11 08:42:05 -0600
committerShane Hathaway <shane@willowrise.com>2021-05-11 08:42:05 -0600
commit22120803fed3bffc61c85c1b1acef8c2d68e620e (patch)
tree26bec8e1e7c4f6bfc90232138c7e4939f80ddb21
parent4b6b5832f3a30d82dc8cb359cf04d2a8edf6712b (diff)
downloadwaitress-22120803fed3bffc61c85c1b1acef8c2d68e620e.tar.gz
Add REMOTE_URI to the WSGI environ.
CHANGES.txt entry included.
-rw-r--r--CHANGES.txt9
-rw-r--r--src/waitress/parser.py3
-rw-r--r--src/waitress/task.py1
-rw-r--r--tests/test_parser.py5
-rw-r--r--tests/test_task.py2
5 files changed, 20 insertions, 0 deletions
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