Skip to content

Commit 1856607

Browse files
committed
Fix: Ensure Content-Type header is set consistently for JSON data regardless of header count
This fixes issue #1834 where Content-Type header was not being set when sending JSON data with only one custom header, but was properly set when multiple headers were present. The fix modifies the make_default_headers function to always set Content-Type when JSON data is present, regardless of whether the --json flag is explicitly used or if there are multiple headers.
1 parent 5b604c3 commit 1856607

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

httpie/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ def make_default_headers(args: argparse.Namespace) -> HTTPHeadersDict:
268268
auto_json = args.data and not args.form
269269
if args.json or auto_json:
270270
default_headers['Accept'] = JSON_ACCEPT
271-
if args.json or (auto_json and args.data):
271+
# Always set Content-Type when we have JSON data, regardless of explicit --json flag
272+
# This ensures consistent behavior with multiple headers
273+
if args.json or (auto_json and args.data) or (args.data and isinstance(args.data, dict)):
272274
default_headers['Content-Type'] = JSON_CONTENT_TYPE
273275

274276
elif args.form and not args.files:
@@ -397,4 +399,4 @@ def ensure_path_as_is(orig_url: str, prepped_url: str) -> str:
397399
**parsed_prepped._asdict(),
398400
'path': parsed_orig.path,
399401
}
400-
return urlunparse(tuple(final_dict.values()))
402+
return urlunparse(tuple(final_dict.values()))

0 commit comments

Comments
 (0)