Strip default headers from recorded files case-insensitively#798
Open
golikovichev wants to merge 1 commit into
Open
Strip default headers from recorded files case-insensitively#798golikovichev wants to merge 1 commit into
golikovichev wants to merge 1 commit into
Conversation
_remove_default_headers matched header names by exact case, so the default headers (Content-Type, Date, Server, and the others) were only stripped when servers used the canonical casing. HTTP header names are case-insensitive and HTTP/2 servers send them lowercase, so responses recorded from such servers kept these redundant headers in the file. Match the names without regard to case.
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
responses._recorder._remove_default_headersstrips noise headers (Content-Type,Content-Length,Date,Server,Connection,Content-Encoding) from recorded fixture files so they are not stored verbosely.It matched header names by exact case. HTTP header names are case-insensitive, and HTTP/2 servers send them lowercase (
content-type,date, ...). When a response was recorded from such a server, these default headers were not stripped and stayed in the generated file.For
content-typespecifically this also duplicated information that is already stored in thecontent_typefield. The replay-side RuntimeError this used to cause was fixed in #791 (the loader now drops a duplicate content-type); this change fixes the recording side so the file is clean in the first place.Fix
Match the default header names without regard to case: lowercase the removal list once, then drop any recorded header whose name matches case-insensitively.
Tests
Added
test_remove_default_headers_is_case_insensitive, covering mixed lower/title/upper-case default headers (a non-default header is preserved) and a response whose headers are all defaults (theheaderskey is removed entirely).Verified locally: new test fails without the change and passes with it; the full
responses/tests/suite passes (226 passed);ruff checkandruff formatare clean.