Skip to content

Commit 15e901a

Browse files
committed
http/message: Split request line as bytes to avoid splitting on 0x0A. Fixes #1577
1 parent ccfb298 commit 15e901a

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

gunicorn/http/message.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def parse(self, unreader):
173173
buf.write(rbuf)
174174
line, rbuf = self.read_line(unreader, buf, self.limit_request_line)
175175

176-
self.parse_request_line(bytes_to_str(line))
176+
self.parse_request_line(line)
177177
buf = BytesIO()
178178
buf.write(rbuf)
179179

@@ -301,10 +301,10 @@ def parse_proxy_protocol(self, line):
301301
"proxy_port": d_port
302302
}
303303

304-
def parse_request_line(self, line):
305-
bits = line.split(None, 2)
304+
def parse_request_line(self, line_bytes):
305+
bits = [bytes_to_str(bit) for bit in line_bytes.split(None, 2)]
306306
if len(bits) != 3:
307-
raise InvalidRequestLine(line)
307+
raise InvalidRequestLine(bytes_to_str(line_bytes))
308308

309309
# Method
310310
if not METH_RE.match(bits[0]):
@@ -325,7 +325,7 @@ def parse_request_line(self, line):
325325
try:
326326
parts = urlsplit(self.uri)
327327
except ValueError:
328-
raise InvalidRequestLine(line)
328+
raise InvalidRequestLine(bytes_to_str(line_bytes))
329329
self.path = parts.path or ""
330330
self.query = parts.query or ""
331331
self.fragment = parts.fragment or ""

tests/requests/valid/027.http

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
GET /à%20k HTTP/1.0\r\n
2+
\r\n

tests/requests/valid/027.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
request = {
2+
"method": "GET",
3+
"uri": uri("/\xc3\xa0%20k"),
4+
"version": (1, 0),
5+
"headers": [
6+
],
7+
"body": ''
8+
}

0 commit comments

Comments
 (0)