Skip to content

Fix recorder producing Content-Type in both content_type and headers#788

Open
worksbyfriday wants to merge 1 commit intogetsentry:masterfrom
worksbyfriday:fix-recorder-content-type-conflict
Open

Fix recorder producing Content-Type in both content_type and headers#788
worksbyfriday wants to merge 1 commit intogetsentry:masterfrom
worksbyfriday:fix-recorder-content-type-conflict

Conversation

@worksbyfriday
Copy link
Contributor

Summary

The recorder stores Content-Type in both the content_type field and the headers dict. When the recorded file is loaded via _add_from_file, both are passed to add(), which raises RuntimeError("You cannot define both content_type and headers[Content-Type]").

The fix excludes Content-Type from the headers dict when recording, since it's already captured in the dedicated content_type field.

Test plan

  • Added test_recorder_excludes_content_type_from_headers — records a response with Content-Type: application/json; charset=UTF-8 and verifies the YAML output has content_type set but no Content-Type in headers
  • All 6 recorder tests pass (no regressions)

Fixes #741

The recorder stores Content-Type in the content_type field AND in
headers, causing RuntimeError when the recorded file is loaded via
_add_from_file (which passes both to add(), triggering the conflict
check).

Fix: exclude Content-Type from the headers dict when recording, since
it's already captured in the content_type field.

Fixes getsentry#741

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Inconsistent Behavior of responses._recorder - content_type and Content-Type Header Conflict

1 participant