Skip to content

fix: set JSON Content-Type when a single header is present#1821

Closed
parinporecha wants to merge 1 commit intohttpie:masterfrom
parinporecha:fix/1640-single-header-json-content-type
Closed

fix: set JSON Content-Type when a single header is present#1821
parinporecha wants to merge 1 commit intohttpie:masterfrom
parinporecha:fix/1640-single-header-json-content-type

Conversation

@parinporecha
Copy link
Copy Markdown

Description

When running http --print=B POST pie.dev/post 'header1: xyz' x=1 with a single custom header, HTTPie doesn't set Content-Type: application/json on the request. With two headers it works fine.

Root Cause

In httpie/client.py lines 263-275, the inner condition if args.json or (auto_json and args.data): was redundant and wrong. It prevented Content-Type from being set when args.json=False and auto_json=True with data.

Fix

Removed the redundant inner if guard. Now Content-Type is set unconditionally inside the outer if args.json or auto_json: block.

Testing

  • Added test test_json_content_type_with_single_header to verify the fix
  • All existing tests pass

Fixes #1640.

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.

JSON content type not being set when a single header is present

1 participant