Skip to content

Commit

Permalink
Merge pull request #3003 from jasonamyers/2977-content-length
Browse files Browse the repository at this point in the history
Updating Content-Length Handling
  • Loading branch information
benoitc committed Jul 10, 2023
2 parents a74b3ed + fa94f70 commit cc2e383
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion gunicorn/http/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ def set_body_reader(self):
self.body = Body(ChunkedReader(self, self.unreader))
elif content_length is not None:
try:
content_length = int(content_length)
if str(content_length).isnumeric():
content_length = int(content_length)
else:
raise InvalidHeader("CONTENT-LENGTH", req=self)
except ValueError:
raise InvalidHeader("CONTENT-LENGTH", req=self)

Expand Down
3 changes: 3 additions & 0 deletions tests/requests/invalid/022.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GET /first HTTP/1.0\r\n
Content-Length: -0\r\n
\r\n
5 changes: 5 additions & 0 deletions tests/requests/invalid/022.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from gunicorn.config import Config
from gunicorn.http.errors import InvalidHeader

cfg = Config()
request = InvalidHeader
3 changes: 3 additions & 0 deletions tests/requests/invalid/023.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GET /first HTTP/1.0\r\n
Content-Length: 0_1\r\n
\r\n
5 changes: 5 additions & 0 deletions tests/requests/invalid/023.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from gunicorn.config import Config
from gunicorn.http.errors import InvalidHeader

cfg = Config()
request = InvalidHeader
3 changes: 3 additions & 0 deletions tests/requests/invalid/024.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GET /first HTTP/1.0\r\n
Content-Length: +1\r\n
\r\n
5 changes: 5 additions & 0 deletions tests/requests/invalid/024.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from gunicorn.config import Config
from gunicorn.http.errors import InvalidHeader

cfg = Config()
request = InvalidHeader

0 comments on commit cc2e383

Please sign in to comment.