summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert JW Regeer <bertjw@regeer.org>2019-08-27 14:08:43 -0600
committerBert JW Regeer <bertjw@regeer.org>2019-08-27 14:17:23 -0600
commit881fc2b4c329dc2db8c710a78cfdae0665268eef (patch)
tree8d060489f63c2079ef63ff204dbb1807e66b50ee
parente88232583f4b3e9c5a8576dcd4672f819e297814 (diff)
downloadwaitress-881fc2b4c329dc2db8c710a78cfdae0665268eef.tar.gz
Allow requests with URI that starts with multiple slashes
The HTTP spec states that it is acceptable to send a request like: GET //whatever/testing HTTP/1.1 This should get properly conveyed to the WSGI application, but due to the way that urlsplit works in the standard library this did not happen correctly. With this fix we pass through the original path as requested by the client, and the WSGI application will be responsible for collapsing multiple empty path segments as necessary. Fixes #260
-rw-r--r--waitress/parser.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/waitress/parser.py b/waitress/parser.py
index e85ede2..c3b28e1 100644
--- a/waitress/parser.py
+++ b/waitress/parser.py
@@ -253,10 +253,23 @@ class HTTPRequestParser(object):
def split_uri(uri):
# urlsplit handles byte input by returning bytes on py3, so
# scheme, netloc, path, query, and fragment are bytes
- try:
- scheme, netloc, path, query, fragment = urlparse.urlsplit(uri)
- except UnicodeError:
- raise ParsingError('Bad URI')
+
+ scheme = netloc = path = query = fragment = b''
+
+ if uri[:2] == b'//':
+ path = uri
+
+ if b'#' in path:
+ path, fragment = path.split(b'#', 1)
+
+ if b'?' in path:
+ path, query = path.split(b'?', 1)
+ else:
+ try:
+ scheme, netloc, path, query, fragment = urlparse.urlsplit(uri)
+ except UnicodeError:
+ raise ParsingError('Bad URI')
+
return (
tostr(scheme),
tostr(netloc),