From 8e1869dc92674c1f52487784d0980979b400848c Mon Sep 17 00:00:00 2001 From: zafar1162014 Date: Mon, 4 May 2026 01:29:06 +0500 Subject: [PATCH] fix: ensure Content-Type is set when sending JSON with custom headers When custom headers are provided alongside JSON data, the Content-Type header should still be set to application/json. Previously, if only a single custom header was provided, the Content-Type was not being set, causing issues with some API gateways that auto-encode request bodies when Content-Type is missing. Fixes #1834 --- httpie/client.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/httpie/client.py b/httpie/client.py index a1da284a7c..8ecf71e51a 100644 --- a/httpie/client.py +++ b/httpie/client.py @@ -344,6 +344,12 @@ def make_request_kwargs( if base_headers: headers.update(base_headers) headers.update(args.headers) + # Ensure Content-Type is set for JSON requests even if user headers + # were provided. This fixes the case where a single custom header + # prevents the default Content-Type from being preserved. + # See: https://github.com/httpie/cli/issues/1834 + if auto_json and 'Content-Type' not in headers: + headers['Content-Type'] = JSON_CONTENT_TYPE if args.offline and args.chunked and 'Transfer-Encoding' not in headers: # When online, we let requests set the header instead to be able more # easily verify chunking is taking place.