Merge pull request #3003 from jasonamyers/2977-content-length

Updating Content-Length Handling
This commit is contained in:
Benoit Chesneau 2023-07-11 00:14:23 +02:00 committed by GitHub
commit cc2e383578
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 1 deletions

View File

@ -139,7 +139,10 @@ class Message(object):
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)

View File

@ -0,0 +1,3 @@
GET /first HTTP/1.0\r\n
Content-Length: -0\r\n
\r\n

View File

@ -0,0 +1,5 @@
from gunicorn.config import Config
from gunicorn.http.errors import InvalidHeader
cfg = Config()
request = InvalidHeader

View File

@ -0,0 +1,3 @@
GET /first HTTP/1.0\r\n
Content-Length: 0_1\r\n
\r\n

View File

@ -0,0 +1,5 @@
from gunicorn.config import Config
from gunicorn.http.errors import InvalidHeader
cfg = Config()
request = InvalidHeader

View File

@ -0,0 +1,3 @@
GET /first HTTP/1.0\r\n
Content-Length: +1\r\n
\r\n

View File

@ -0,0 +1,5 @@
from gunicorn.config import Config
from gunicorn.http.errors import InvalidHeader
cfg = Config()
request = InvalidHeader