Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: header calculation #376

Merged
merged 2 commits into from Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/waitress/parser.py
Expand Up @@ -103,7 +103,7 @@ def received(self, data):
# If the headers have ended, and we also have part of the body
# message in data we still want to validate we aren't going
# over our limit for received headers.
self.header_bytes_received += index
self.header_bytes_received = index
consumed = datalen - (len(s) - index)
else:
self.header_bytes_received += datalen
Expand Down
12 changes: 12 additions & 0 deletions tests/test_parser.py
Expand Up @@ -106,6 +106,18 @@ def test_received_cl_too_large(self):
self.assertTrue(self.parser.completed)
self.assertTrue(isinstance(self.parser.error, RequestEntityTooLarge))

def test_received_headers_not_too_large_multiple_chunks(self):

data = b"GET /foobar HTTP/8.4\r\nX-Foo: 1\r\n"
data2 = b"X-Foo-Other: 3\r\n\r\n"
self.parser.adj.max_request_header_size = len(data) + len(data2) + 1
result = self.parser.received(data)
self.assertEqual(result, 32)
result = self.parser.received(data2)
self.assertEqual(result, 18)
self.assertTrue(self.parser.completed)
self.assertFalse(self.parser.error)

def test_received_headers_too_large(self):

self.parser.adj.max_request_header_size = 2
Expand Down