Skip to content

Fix: Ensure Content-Type: application/json is set when JSON data is sent with custom headers - #1910

Closed
vinayK34 wants to merge 2 commits into
httpie:masterfrom
vinayK34:fix/json-content-type-header-issue
Closed

Fix: Ensure Content-Type: application/json is set when JSON data is sent with custom headers#1910
vinayK34 wants to merge 2 commits into
httpie:masterfrom
vinayK34:fix/json-content-type-header-issue

Conversation

@vinayK34

Copy link
Copy Markdown

This PR fixes an issue where the Content-Type: application/json header was not being set properly when sending POST requests with JSON data and a single custom header.

Root Cause:
The issue was in the apply_missing_repeated_headers function in httpie/client.py. When there's only one custom header, the header merging logic incorrectly interfered with the automatic setting of the Content-Type: application/json header that should be applied when JSON data is sent.

Fix:
Modified the apply_missing_repeated_headers function to detect when Content-Type was automatically set for JSON data and preserve it during header processing, regardless of the number of custom headers present.

Testing:

  • The fix ensures consistent behavior whether there are 0, 1, or multiple custom headers
  • When JSON data is sent, Content-Type: application/json is always preserved
  • When multiple custom headers are present, the behavior remains unchanged

vinayK34 added 2 commits July 29, 2026 00:35
…ent with custom headers

The issue was in the `apply_missing_repeated_headers` function in `httpie/client.py`. When sending a POST request with JSON data and a single custom header, the automatic Content-Type: application/json header was not being preserved properly due to incorrect header merging logic.

This fix preserves the automatic Content-Type header for JSON data even when there's only one custom header present, ensuring consistent behavior regardless of the number of custom headers.
@vinayK34 vinayK34 closed this by deleting the head repository Jul 29, 2026
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