Two years ago

What’s new in HTTPie for Terminal 2.6.0

Body charset detection

If a message’s Content-Type header doesn’t specify charset, HTTPie now auto-detects it from the body content, and then uses this information to correctly display the text on the terminal.

# Preview a Big5-encoded request w/o charset in Content-Type:
echo  '維基大典維基大典維基大典維基大典' \
    | iconv -f utf8 -t big5 \
    | http --offline pie.dev Content-Type:text/plain
Run

Prior to HTTPie 2.6.0:

POST / HTTP/1.1
Content-Type: text/plain

����j�����j�����j�����j��

With 2.6.0:

POST / HTTP/1.1
Content-Type: text/plain

維基大典維基大典維基大典維基大典

You can learn more about displaying encoding in the docs.

Response charset overwrite

When the server includes an incorrect charset in Content-Type, you can now overwrite that value for display purposes.

For example, the following response incorrectly specifies charset=utf-8:

$ http -F https://git.io/JiOaA
Run
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8

����j��]Wikipedia�

We can now fix that with --response-charset:

$ http -F --response-charset=big5 https://git.io/JiOaA
Run
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8

維基大典(Wikipedia)

Response MIME overwrite

HTTPie looks at Content-Type to select the right syntax highlighter and formatter for each message body. If that fails (e.g., the server provides the wrong type), or you prefer a different treatment, you can now manually overwrite the mime type for the response with --response-mime. For example, here we’re formatting and colorizing a JSON response as if it were YAML:

$ http --response-mime=text/yaml pie.dev/get
Run

XSSI prefixes no longer break JSON formatting

HTTPie can now handle extraneous data preceding a JSON body. For example, when an API uses an XSSI prefix.

Prior to HTTPie 2.6.0:

for(;;){"status": -1, "error":"The resource requires authentication."}

With 2.6.0, we highlight the non-JSON prefix, and then correctly format and color the rest:

for(;;)
{
    "error": "The resource requires authentication.",
    "status": -1
}

Duplicate JSON keys are now preserved

JSON doesn’t disallow repeated keys. However, before HTTPie 2.6.0, we’d incorrectly show only the last occurrence as a result of formatting the JSON:

$ http --print=B --offline --raw='{"A": 1,"A":2}' pie.dev

Prior to HTTPie 2.6.0:

{
    "A": 2
}

Starting with HTTPie 2.6.0, we preserve all keys as shown below:

{
    "A": 1,
    "A": 2
}

Other improvements

  • Silence warnings through using --quiet, -q twice (e.g. -qq) (#1175).
  • List installed plugin list to --debug output (#1165).

Community contributions

We’d like to thank these amazing people for their contributions to this release: Annette Wilson, Dave, Fabio Peruzzo, Miro Hrončok, Omer Akram, Vincent van ’t Zand, dkreeft, 崔小二, and 黄海.