Skip to content

Commit

Permalink
Merge pull request #344 from hathawsh/add-remote-uri
Browse files Browse the repository at this point in the history
Add REQUEST_URI
  • Loading branch information
digitalresistor committed May 15, 2021
2 parents 4b6b583 + c68c904 commit 84cfc2b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
9 changes: 9 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
Next Release
------------

- Add REQUEST_URI to the WSGI environment.

REQUEST_URI is similar to ``request_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)
------------------

Expand Down
4 changes: 2 additions & 2 deletions src/waitress/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


class ClientDisconnected(Exception):
""" Raised when attempting to write to a closed socket."""
"""Raised when attempting to write to a closed socket."""


class HTTPChannel(wasyncore.dispatcher):
Expand Down Expand Up @@ -480,7 +480,7 @@ def service(self):
self.last_activity = time.time()

def cancel(self):
""" Cancels all pending / active requests """
"""Cancels all pending / active requests"""
self.will_close = True
self.connected = False
self.last_activity = time.time()
Expand Down
3 changes: 3 additions & 0 deletions src/waitress/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ def parse_header(self, header_plus):

# 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
Expand Down
1 change: 1 addition & 0 deletions src/waitress/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ def get_environment(self):
"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
Expand Down
5 changes: 5 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,11 @@ def testComplexGET(self):
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"
)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ def test_get_environment_values(self):
"REMOTE_HOST",
"REMOTE_PORT",
"REQUEST_METHOD",
"REQUEST_URI",
"SCRIPT_NAME",
"SERVER_NAME",
"SERVER_PORT",
Expand Down Expand Up @@ -982,6 +983,7 @@ class DummyParser:
version = "1.0"
command = "GET"
path = "/"
request_uri = "/"
query = ""
url_scheme = "http"
expect_continue = False
Expand Down

0 comments on commit 84cfc2b

Please sign in to comment.