Repository navigation
Handle non-UTF8 response header values - #220
Open
dhairyajangir wants to merge 1 commit into
Open
dhairyajangir wants to merge 1 commit into
dhairyajangir wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #143.
Session.get()raisesUnicodeErrorwhen an ordinary response header contains a Latin-1 byte such as0xF6, before its valid body can be read.Keep the existing UTF-8 conversion first. When it fails, map the original header-value octets to their corresponding Unicode code points using a small UTF-8 bytearray helper. This preserves the supplied value without needing a Latin-1 runtime codec. Header-name decoding and body decoding retain their existing paths.
Keep invalid UTF-8
Content-LengthandTransfer-Encodingvalues on their original error path. In particular, converting a raw NBSP must not make an invalid framing value recognizable through Unicode whitespace handling.HTTP field-value rules permit opaque high octets. The helper uses the UTF-8/buffer APIs supported by CircuitPython.
Validation:
Tests cover ASCII and existing UTF-8 behavior, Latin-1 and mixed/opaque values, the complete high-octet range, colons, duplicate cookies, chunked bodies, UTF-8 bodies, and invalid names/framing. Host validation used CPython 3.11.17; target API compatibility was checked against current and stable CircuitPython source. Board execution and heap measurements remain untested.
Codex assisted reproduction, implementation and validation.