Skip to content

Add keep_headers to the recorder to preserve named default headers - #809

Open
golikovichev wants to merge 1 commit into
getsentry:masterfrom
golikovichev:fix/763-recorder-keep-headers
Open

Add keep_headers to the recorder to preserve named default headers#809
golikovichev wants to merge 1 commit into
getsentry:masterfrom
golikovichev:fix/763-recorder-keep-headers

Conversation

@golikovichev

Copy link
Copy Markdown
Contributor

Summary

Closes #763.

The recorder strips a fixed set of verbose default headers (Content-Length, Content-Type, Date, Server, Connection, Content-Encoding) so recorded files stay terse. That is the right default, but it makes one use case impossible: a response whose signature covers the Date header cannot be verified against a recording, because the recorded file no longer has the Date value.

This adds an opt-in keep_headers argument that excludes named headers from the default stripping:

@_recorder.record(file_path="out.yaml", keep_headers=["Date"])
def test_recorder():
    ...
  • Available on both record and dump_to_file.
  • Matched case-insensitively, consistent with the existing default-header handling (a lowercase HTTP/2 date is kept too).
  • A bare string is treated as a single header name, so keep_headers="Date" does the expected thing rather than iterating over characters.
  • Defaults to None, so existing recordings are byte-for-byte unchanged.

Tests

  • Unit tests on _remove_default_headers: a named header is kept while the other defaults are still stripped; a bare string is accepted; naming a non-default header is a no-op.
  • An end-to-end test through record() that preserves Date with the flag and confirms it is stripped without it.

CHANGES and the README recorder section are updated.

The recorder strips a fixed set of verbose default headers (Content-Type,
Date, Server and so on) to keep recorded files terse. Some responses need
one of them kept: a signed response whose signature covers the Date header
cannot be verified against a recording that dropped it.

Add a keep_headers argument to record and dump_to_file that excludes the
named headers from the default stripping, matched case-insensitively. A bare
string is treated as a single header name. Defaults to None, so existing
recordings are unchanged.

Closes getsentry#763
@golikovichev
golikovichev requested a review from markstory as a code owner July 27, 2026 18:00
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.

recorder doesn't record Date header

1 participant