fix(client): normalize headers and response handling for local /request#106
Open
Miskler wants to merge 6 commits intodaijro:mainfrom
Open
fix(client): normalize headers and response handling for local /request#106Miskler wants to merge 6 commits intodaijro:mainfrom
Miskler wants to merge 6 commits intodaijro:mainfrom
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.
Problem
The TLS client implementation was brittle in multiple places:
Response body: server sometimes returned
bytearray(...), HTML error pages, or gzip-encoded data → JSON decoding failed withorjson.JSONDecodeError.Response headers:
geventhttpclientexposed headers as generators orbytes, not as a cleandict, causing.items()errors and type mismatches.Request headers: outgoing headers mixed
strandbytesor contained non-string values (int), leading toTypeError: can't concat str to bytesingeventhttpclient;BrowserContext.set_extra_http_headers: expected string, got numberwhen rendering with Playwright.When it happens
bytearray(...)wrappers, gzip).bytes, or numeric values)./requestwithout a properContent-Type: application/json..render(), if any header value is not a string (e.g.X-City: 229as an integer).Solution
Added
_normalize_headersto coerce any header format (generator,bytes, tuples) intodict[str,str|list[str]].Introduced
_SanitizedCID, aCaseInsensitiveDictsubclass, that forces all header values tostron insert/update.Outgoing requests to
/requestnow always usegeventhttpclient.header.HeaderswithContent-Type: application/jsonandAccept: application/json.Response body is read once and normalized:
Content-Encoding: gzip;bytearray(...)repr if present;Minor fixes: safe handling of
timeoutMilliseconds,insecureSkipVerify, and base64 only for true byte bodies.Improved error messages with safe body prefixes for diagnostics.
Result
geventhttpclientor Playwright.