Skip to content

Strip default headers from recorded files case-insensitively#798

Open
golikovichev wants to merge 1 commit into
getsentry:masterfrom
golikovichev:fix/765-recorder-content-type
Open

Strip default headers from recorded files case-insensitively#798
golikovichev wants to merge 1 commit into
getsentry:masterfrom
golikovichev:fix/765-recorder-content-type

Conversation

@golikovichev

Copy link
Copy Markdown

Problem

responses._recorder._remove_default_headers strips 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-type specifically this also duplicated information that is already stored in the content_type field. 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 (the headers key is removed entirely).

Verified locally: new test fails without the change and passes with it; the full responses/tests/ suite passes (226 passed); ruff check and ruff format are clean.

_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.
@golikovichev golikovichev requested a review from markstory as a code owner June 14, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant