Fix JSON Content-Type not set when single header present#1842
Open
mitre88 wants to merge 1 commit intohttpie:masterfrom
Open
Fix JSON Content-Type not set when single header present#1842mitre88 wants to merge 1 commit intohttpie:masterfrom
mitre88 wants to merge 1 commit intohttpie:masterfrom
Conversation
When a single custom header is passed with JSON body data, the Content-Type header was being overwritten because headers.update() was called after base_headers but after args.headers. The order is now: 1. make_default_headers (sets Content-Type for JSON) 2. headers.update(args.headers) (applies custom headers) 3. base_headers.update() (if provided) This ensures user-provided headers don't incorrectly override the auto-detected JSON Content-Type when body data exists. Fixes issue httpie#1834
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
When a single custom header is passed with JSON body data, the Content-Type header was not being set correctly.
Problem
The order of header updates was incorrect:
But args.headers.update() was overwriting the auto-detected JSON Content-Type because
auto_jsonandargs.jsoncheckargs.data, which at that point is an empty dict (which is falsy).Fix
Reordered the header updates:
This ensures Content-Type is correctly set when body data exists, even with a single custom header.
Fixes issue #1834