Skip to content

Commit

Permalink
Update tests to remove invalid chunked encoding chunk-size
Browse files Browse the repository at this point in the history
RFC7230 states the following:

     chunk          = chunk-size [ chunk-ext ] CRLF
                      chunk-data CRLF
     chunk-size     = 1*HEXDIG

Where chunk-ext is:

     chunk-ext      = *( ";" chunk-ext-name [ "=" chunk-ext-val ] )

Only if there is a chunk-ext should there be a `;` after the 1*HEXDIG.
And a chunk-ext that is empty is invalid.
  • Loading branch information
digitalresistor committed Mar 13, 2022
1 parent 1f6059f commit 884bed1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def test_chunking_request_without_content(self):
self.assertFalse("transfer-encoding" in headers)

def test_chunking_request_with_content(self):
control_line = b"20;\r\n" # 20 hex = 32 dec
control_line = b"20\r\n" # 20 hex = 32 dec
s = b"This string has 32 characters.\r\n"
expected = s * 12
header = b"GET / HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n"
Expand All @@ -341,7 +341,7 @@ def test_chunking_request_with_content(self):
self.assertFalse("transfer-encoding" in headers)

def test_broken_chunked_encoding(self):
control_line = b"20;\r\n" # 20 hex = 32 dec
control_line = b"20\r\n" # 20 hex = 32 dec
s = b"This string has 32 characters.\r\n"
to_send = b"GET / HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n"
to_send += control_line + s + b"\r\n"
Expand All @@ -365,7 +365,7 @@ def test_broken_chunked_encoding(self):
self.assertRaises(ConnectionClosed, read_http, fp)

def test_broken_chunked_encoding_missing_chunk_end(self):
control_line = b"20;\r\n" # 20 hex = 32 dec
control_line = b"20\r\n" # 20 hex = 32 dec
s = b"This string has 32 characters.\r\n"
to_send = b"GET / HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n"
to_send += control_line + s
Expand Down
2 changes: 1 addition & 1 deletion tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def test_received_chunked_completed_sets_content_length(self):
b"Transfer-Encoding: chunked\r\n"
b"X-Foo: 1\r\n"
b"\r\n"
b"1d;\r\n"
b"1d\r\n"
b"This string has 29 characters\r\n"
b"0\r\n\r\n"
)
Expand Down

0 comments on commit 884bed1

Please sign in to comment.