Skip to content

Commit b4399ca

Browse files
committed
feat: support for plain HTTP client connection with no length
For those connection it's expected to have the data processed at the connection closed (EOF). The final solution was to create the `parse_closed()` HTTPParser operation which bring semantics to the closing of a connection.
1 parent 0efed28 commit b4399ca

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12-
*
12+
* Support for HTTP client handling of plain HTTP message with no content length defined - finished at connection closed
1313

1414
### Changed
1515

src/netius/clients/http.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ def close_c(self, *args, **kwargs):
247247
netius.StreamProtocol.close_c(self, *args, **kwargs)
248248

249249
if self.parser:
250+
self.parser.parse_closed()
250251
self.parser.destroy()
251252
if self.parsed:
252253
self.parsed = None

src/netius/common/http.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,20 @@ def get_encodings(self):
459459
self.encodings = [value.strip() for value in accept_encoding_s.split(",")]
460460
return self.encodings
461461

462+
def parse_closed(self):
463+
"""
464+
"Parses" the closed event, which may trigger a changed in state
465+
for very specific conditions, which is the case of a plain encoded
466+
connection with no explicit content length defined.
467+
468+
In these situations the closing of a connection should be seen as
469+
the sending of a EOF character (with semantic value).
470+
"""
471+
472+
if not self.chunked and self.content_l == -1 and self.state == MESSAGE_STATE:
473+
self.state = FINISH_STATE
474+
self.trigger("on_data")
475+
462476
def parse(self, data):
463477
"""
464478
Parses the provided data chunk, changing the current

src/netius/servers/wsgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def _start_response(self, connection, status, headers):
243243

244244
# tries to determine if the accept ranges value is set and if
245245
# that's the case forces the uncompressed encoding to avoid possible
246-
# range missmatch due to re-encoding of the content
246+
# range mismatch due to re-encoding of the content
247247
ranges = headers.get("Accept-Ranges", None)
248248
if ranges == "bytes":
249249
connection.set_uncompressed()

0 commit comments

Comments
 (0)