Skip to content

Commit

Permalink
http/message: Split request line as bytes to avoid splitting on 0x0A. F…
Browse files Browse the repository at this point in the history
…ixes benoitc#1577
  • Loading branch information
rslinckx committed Aug 25, 2017
1 parent ccfb298 commit 15e901a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
10 changes: 5 additions & 5 deletions gunicorn/http/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def parse(self, unreader):
buf.write(rbuf)
line, rbuf = self.read_line(unreader, buf, self.limit_request_line)

self.parse_request_line(bytes_to_str(line))
self.parse_request_line(line)
buf = BytesIO()
buf.write(rbuf)

Expand Down Expand Up @@ -301,10 +301,10 @@ def parse_proxy_protocol(self, line):
"proxy_port": d_port
}

def parse_request_line(self, line):
bits = line.split(None, 2)
def parse_request_line(self, line_bytes):
bits = [bytes_to_str(bit) for bit in line_bytes.split(None, 2)]
if len(bits) != 3:
raise InvalidRequestLine(line)
raise InvalidRequestLine(bytes_to_str(line_bytes))

# Method
if not METH_RE.match(bits[0]):
Expand All @@ -325,7 +325,7 @@ def parse_request_line(self, line):
try:
parts = urlsplit(self.uri)
except ValueError:
raise InvalidRequestLine(line)
raise InvalidRequestLine(bytes_to_str(line_bytes))
self.path = parts.path or ""
self.query = parts.query or ""
self.fragment = parts.fragment or ""
Expand Down
2 changes: 2 additions & 0 deletions tests/requests/valid/027.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GET /à%20k HTTP/1.0\r\n
\r\n
8 changes: 8 additions & 0 deletions tests/requests/valid/027.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
request = {
"method": "GET",
"uri": uri("/\xc3\xa0%20k"),
"version": (1, 0),
"headers": [
],
"body": ''
}

0 comments on commit 15e901a

Please sign in to comment.