Skip to content

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

Open

Description

@gargantuanprism

Checklist

  • I've searched for similar issues.
  • I'm using the latest version of HTTPie.

Minimal reproduction code and steps

  1. $ https post pie.dev/post -v 'header1: xyz' x=1
  2. $ https post pie.dev/post -v 'header1: xyz' 'header2: abc' x=1

Current result

output from step 1:

POST /post HTTP/1.1
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: pie.dev
header1: xyz

{"x": "1"}

HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
CF-RAY: 95566dc8c8d1f7c9-LAX
Cf-Cache-Status: DYNAMIC
Connection: keep-alive
Content-Encoding: gzip
Content-Type: application/json
Date: Wed, 25 Jun 2025 18:11:41 GMT
Nel: {"report_to":"cf-nel","success_fraction":0.0,"max_age":604800}
Report-To: {"group":"cf-nel","max_age":604800,"endpoints":[{"url":"https://a.nel.cloudflare.com/report/v4?s=T5F5MLxiQSAvDrINeG1ku5IkxuGFXPCXZCppIMBEnShUajvjeC3%2BvZcwVBmdlCmAv4Nb9LuUyx2EnQd45Dnmkx%2FAojwaiPk%3D"}]}
Server: cloudflare
Transfer-Encoding: chunked
alt-svc: h3=":443"; ma=86400

{
    "args": {},
    "data": "{\"x\": \"1\"}",
    "files": {},
    "form": {},
    "headers": {
        "Accept-Encoding": "gzip, br",
        "Cdn-Loop": "cloudflare; loops=1",
        "Cf-Connecting-Ip": "<REDACTED>",
        "Cf-Ipcountry": "US",
        "Cf-Ray": "95566dc8c8d1f7c9-FRA",
        "Cf-Visitor": "{\"scheme\":\"https\"}",
        "Content-Length": "10",
        "Header1": "xyz",
        "Host": "pie.dev",
        "User-Agent": "python-urllib3/2.5.0"
    },
    "json": {
        "x": "1"
    },
    "origin": "<REDACTED>",
    "url": "https://pie.dev/post"
}

(Neither HTTPie's verbose output or pie.dev's response reports Content-Type: application/json)
…

Expected result

output from step 2:

POST /post HTTP/1.1
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Type: application/json
header1: xyz
header2: abc
Host: pie.dev

{"x": "1"}

HTTP/1.1 200 OK
Date: Wed, 25 Jun 2025 18:13:03 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Server: cloudflare
Nel: {"report_to":"cf-nel","success_fraction":0.0,"max_age":604800}
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Cf-Cache-Status: DYNAMIC
Report-To: {"group":"cf-nel","max_age":604800,"endpoints":[{"url":"https://a.nel.cloudflare.com/report/v4?s=rtMPq5%2BI8UInMXCz1Fm7mh3yvd5yUt%2BZrSaQMEqe68bvTDT0Aka8A3gc8wSEQP1ZNkbhXMV6QB%2FcyVjAgpW04b439a9nRYM%3D"}]}
Content-Encoding: gzip
CF-RAY: 95566fc8bb3c279a-LAX
alt-svc: h3=":443"; ma=86400

{
  "args": {}, 
  "data": "{\"x\": \"1\"}", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept-Encoding": "gzip, br", 
    "Cdn-Loop": "cloudflare; loops=1", 
    "Cf-Connecting-Ip": "<REDACTED>", 
    "Cf-Ipcountry": "US", 
    "Cf-Ray": "95566fc8bb3c279a-FRA", 
    "Cf-Visitor": "{\"scheme\":\"https\"}", 
    "Content-Length": "10", 
    "Content-Type": "application/json", 
    "Header1": "xyz", 
    "Header2": "abc", 
    "Host": "pie.dev", 
    "User-Agent": "python-urllib3/2.5.0"
  }, 
  "json": {
    "x": "1"
  }, 
  "origin": "<REDACTED>", 
  "url": "https://pie.dev/post"
}

(both HTTPie's verbose output and pie.dev's response report Content-Type: application/json)
…


Debug output

Please re-run the command with --debug, then copy the entire command & output and paste both below:

$ https post pie.dev/post --debug -v 'header1: xyz' x=1

HTTPie 3.2.4
Requests 2.32.4
Pygments 2.19.1
Python 3.13.5 (main, Jun 11 2025, 15:36:57) [Clang 17.0.0 (clang-1700.0.13.3)]
/opt/homebrew/Cellar/httpie/3.2.4_3/libexec/bin/python
Darwin 24.5.0

<Environment {'apply_warnings_filter': <function Environment.apply_warnings_filter at 0x101b88cc0>,
 'args': Namespace(),
 'as_silent': <function Environment.as_silent at 0x101b88b80>,
 'colors': 256,
 'config': {'default_options': []},
 'config_dir': PosixPath('/Users/andrewmuro/.config/httpie'),
 'devnull': <property object at 0x101b66a70>,
 'is_windows': False,
 'log_error': <function Environment.log_error at 0x101b88c20>,
 'program_name': 'https',
 'quiet': 0,
 'rich_console': <functools.cached_property object at 0x10103e690>,
 'rich_error_console': <functools.cached_property object at 0x101b5cc00>,
 'show_displays': True,
 'stderr': <_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>,
 'stderr_isatty': True,
 'stdin': <_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>,
 'stdin_encoding': 'utf-8',
 'stdin_isatty': True,
 'stdout': <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>,
 'stdout_encoding': 'utf-8',
 'stdout_isatty': True}>

<PluginManager {'adapters': [],
 'auth': [<class 'httpie.plugins.builtin.BasicAuthPlugin'>,
          <class 'httpie.plugins.builtin.DigestAuthPlugin'>,
          <class 'httpie.plugins.builtin.BearerAuthPlugin'>],
 'converters': [],
 'formatters': [<class 'httpie.output.formatters.headers.HeadersFormatter'>,
                <class 'httpie.output.formatters.json.JSONFormatter'>,
                <class 'httpie.output.formatters.xml.XMLFormatter'>,
                <class 'httpie.output.formatters.colors.ColorFormatter'>]}>

>>> requests.request(**{'auth': None,
 'data': b'{"x": "1"}',
 'headers': <HTTPHeadersDict('User-Agent': b'HTTPie/3.2.4', 'Accept': b'application/json, */*;q=0.5', 'Content-Type': b'application/json', 'header1': b'xyz')>,
 'method': 'post',
 'params': <generator object MultiValueOrderedDict.items at 0x101facf40>,
 'url': 'https://pie.dev/post'})

POST /post HTTP/1.1
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: pie.dev
header1: xyz

{"x": "1"}

HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
CF-RAY: 95567851aa815263-LAX
Cf-Cache-Status: DYNAMIC
Connection: keep-alive
Content-Encoding: gzip
Content-Type: application/json
Date: Wed, 25 Jun 2025 18:18:53 GMT
Nel: {"report_to":"cf-nel","success_fraction":0.0,"max_age":604800}
Report-To: {"group":"cf-nel","max_age":604800,"endpoints":[{"url":"https://a.nel.cloudflare.com/report/v4?s=esCpq2VXduYA9W9gSJ1M5zi9BdGYBrkJ8fq8Jc8tIJf2QEO4REGWcuonYlkM5cAHzETL%2BPuzAcAuyUgokl6O74%2F7D53b"}]}
Server: cloudflare
Transfer-Encoding: chunked
alt-svc: h3=":443"; ma=86400

{
    "args": {},
    "data": "{\"x\": \"1\"}",
    "files": {},
    "form": {},
    "headers": {
        "Accept-Encoding": "gzip, br",
        "Cdn-Loop": "cloudflare; loops=1",
        "Cf-Connecting-Ip": "<REDACTED>",
        "Cf-Ipcountry": "US",
        "Cf-Ray": "95567851aa815263-FRA",
        "Cf-Visitor": "{\"scheme\":\"https\"}",
        "Content-Length": "10",
        "Header1": "xyz",
        "Host": "pie.dev",
        "User-Agent": "python-urllib3/2.5.0"
    },
    "json": {
        "x": "1"
    },
    "origin": "<REDACTED>",
    "url": "https://pie.dev/post"
}

Additional information, screenshots, or code examples

The underlying issue here is that when sending a request to a Serverless app (in my case, using only an Authorization header), API gateway will automatically encode the request body as base64 because the Content-Type header isn't set, which causes JSON parsing of the body to fail.
…

Activity

  1. added
    bugSomething isn't working
    newNeeds triage. Comments are welcome!
    on Jun 25, 2025
  2. rjw57 commented on Jun 26, 2025

    @rjw57

    We're also running into this issue. It's possibly related to #1637.

    This may be fixed by upgrading the multidict dependency or re-installing httpie which will bring in a fresh install of multidict.

    In our case we're having to pin our httpie version to 3.2.3 as we are using the alpine/httpie docker image which won't get updated until there is a new httpie release to trigger it. (See alpine-docker/multi-arch-docker-images#23. This is, of course, not the httpie project's problem to solve, I'm including that as additional information for anyone else who ends up here from Google.)

  3. Oluwasetemi commented on Jul 5, 2025

    @Oluwasetemi

    I am experiencing this issue as well

  4. deer-roy commented on Jul 21, 2025

    @deer-roy

    Just got hit with this one as well. Had to switch to switch to curl which wasn't very fun but I suppose it got the job done.

  5. worksbyfriday commented on Feb 17, 2026

    @worksbyfriday

    This appears to be the same root cause as #1637 — a regression in multidict 6.5.0 that broke CIMultiDict.popone(), which httpie's apply_missing_repeated_headers() relies on.

    The multidict bug was fixed in aio-libs/multidict#1196 and multidict 6.5.0 was yanked from PyPI, so fresh installs now get 6.4.4 or 6.5.1+.

    If you're still hitting this (e.g., via Homebrew or a cached pip install), upgrading multidict should fix it:

    pip install --upgrade multidict
    

    For Homebrew users, a brew reinstall httpie should pick up the corrected dependency.

  6. gargantuanprism commented on Feb 19, 2026

    @gargantuanprism
    Author

    my fix ended up being that i switched to xh instead 🫤

  7. added a commit that references this issue on Apr 18, 2026
    77b8ae0
  8. Ti-03 commented on Jun 5, 2026

    @Ti-03

    Confirmed — root cause is multidict 6.5.0, as @gargantuanprism noted. Here's an isolated reproduction that pins the dependency to prove it.

    Environment

    • macOS (Darwin 25.5.0), Apple Silicon
    • HTTPie 3.2.4, Requests 2.34.2, Python 3.13.13
    • Fresh uv venv; the only variable changed between runs is multidict

    Steps & outcome

    With multidict==6.5.0 (the yanked version):

    $ http --print=H --ignore-stdin post pie.dev/post 'header1: xyz' x=1
    # → NO `Content-Type: application/json` in the request  ❌  (bug)
    
    $ http --print=H --ignore-stdin post pie.dev/post 'header1: xyz' 'header2: abc' x=1
    # → `Content-Type: application/json` present  ✅
    

    I also confirmed it's actually sent that way (not just a display quirk) — pie.dev echoes back "Content-Type": <none> for the single-header request.

    After pip install -U multidict (got 6.7.1):

    $ http --print=H --ignore-stdin post pie.dev/post 'header1: xyz' x=1
    # → `Content-Type: application/json` present  ✅  (fixed)
    

    The trigger is exactly one custom header: 0, 2, and 3 headers all keep Content-Type; only a single header drops it, and only on multidict==6.5.0. Since 6.5.0 is yanked, fresh installs resolve to a non-yanked version (I got 6.7.1) and won't see this. Anyone still hitting it (Homebrew, a Docker pin, or a cached install) should run pip install -U multidict.


    Reduced to a pure-Python MCVE (no httpie, no network). The whole thing boils down to a multidict popone() + update() regression on a 5-key map:

    from multidict import CIMultiDict
    md = CIMultiDict({"a":"1","b":"2","c":"3","d":"4","e":"5"})
    md.popone("a")            # remove first key
    md.update([("a","1")])    # add it back
    assert set(md.keys()) == {"a","b","c","d","e"}  # fails on multidict==6.5.0

    On multidict==6.5.0 this drops a key and raises; on 6.5.1+ it passes. Exactly 5 keys is the minimum that trips it (4 and 6 don't). It matches the regression test added in the upstream fix (aio-libs/multidict#1196, tracked as aio-libs/multidict#1195). httpie's apply_missing_repeated_headers() does this same popone()-then-update() sequence, which is why a single custom header drops Content-Type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingnewNeeds triage. Comments are welcome!

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions