Add keep_headers to the recorder to preserve named default headers - #809
Open
golikovichev wants to merge 1 commit into
Open
Add keep_headers to the recorder to preserve named default headers#809golikovichev wants to merge 1 commit into
golikovichev wants to merge 1 commit into
Conversation
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
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.
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 theDateheader cannot be verified against a recording, because the recorded file no longer has theDatevalue.This adds an opt-in
keep_headersargument that excludes named headers from the default stripping:recordanddump_to_file.dateis kept too).keep_headers="Date"does the expected thing rather than iterating over characters.None, so existing recordings are byte-for-byte unchanged.Tests
_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.record()that preservesDatewith the flag and confirms it is stripped without it.CHANGESand the README recorder section are updated.