Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions httptools/parser/parser.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,7 @@ cdef int cb_on_headers_complete(cparser.llhttp_t* parser) except -1:
pyparser._last_error = ex
return -1
else:
if pyparser._cparser.upgrade:
return 1
else:
return 0
return 0


cdef int cb_on_body(cparser.llhttp_t* parser,
Expand Down
25 changes: 25 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,31 @@ def on_message_complete(self):
else:
self.fail('HttpParserUpgrade was not raised')

def test_parser_request_upgrade_with_body(self):
next_request = b'GET / HTTP/1.1\r\n\r\n'
for framing, body, expected in [
(b'Content-Length: 5', b'hello', [b'hello']),
(b'Transfer-Encoding: chunked', b'3\r\nabc\r\n0\r\n\r\n', [b'abc']),
]:
with self.subTest(framing=framing):
request = (
b'POST / HTTP/1.1\r\n'
b'Connection: Upgrade, HTTP2-Settings\r\n'
b'Upgrade: h2c\r\n'
b'HTTP2-Settings: AAMAAABkAAQAoAAAAAIAAAAA\r\n'
+ framing + b'\r\n\r\n' + body
)
m = mock.Mock()
p = httptools.HttpRequestParser(m)

with self.assertRaises(httptools.HttpParserUpgrade) as cm:
p.feed_data(request + next_request)

self.assertEqual(cm.exception.args[0], len(request))
self.assertEqual(
[c.args[0] for c in m.on_body.call_args_list], expected)
m.on_message_complete.assert_called_once_with()

def test_parser_request_error_in_on_header(self):
class Error(Exception):
pass
Expand Down
Loading