1515from typing import TypeVar , Optional , Dict , Type , Tuple , List
1616
1717from ...common .constants import DEFAULT_DISABLE_HEADERS , COLON , DEFAULT_ENABLE_PROXY_PROTOCOL
18- from ...common .constants import HTTP_1_1 , HTTP_1_0 , SLASH , CRLF
18+ from ...common .constants import HTTP_1_1 , SLASH , CRLF
1919from ...common .constants import WHITESPACE , DEFAULT_HTTP_PORT
2020from ...common .utils import build_http_request , build_http_response , find_http_line , text_
2121from ...common .flag import flags
@@ -271,7 +271,7 @@ def _process_body(self, raw: bytes) -> Tuple[bool, bytes]:
271271 self .body = self .chunk .body
272272 self .state = httpParserStates .COMPLETE
273273 more = False
274- elif b'content-length' in self .headers :
274+ elif self .content_expected :
275275 self .state = httpParserStates .RCVING_BODY
276276 if self .body is None :
277277 self .body = b''
@@ -283,13 +283,15 @@ def _process_body(self, raw: bytes) -> Tuple[bool, bytes]:
283283 self .state = httpParserStates .COMPLETE
284284 more , raw = len (raw ) > 0 , raw [total_size - received_size :]
285285 else :
286- # HTTP/1.0 scenario only
287- assert self .version == HTTP_1_0
288286 self .state = httpParserStates .RCVING_BODY
289287 # Received a packet without content-length header
290288 # and no transfer-encoding specified.
291289 #
290+ # This can happen for both HTTP/1.0 and HTTP/1.1 scenarios.
291+ # Currently, we consume the remaining buffer as body.
292+ #
292293 # Ref https://github.com/abhinavsingh/proxy.py/issues/398
294+ #
293295 # See TestHttpParser.test_issue_398 scenario
294296 self .body = raw
295297 more , raw = False , b''
0 commit comments