DEV Community 👩‍💻👨‍💻

Cover image for What’s new in HTTPie 2.6.0
Jakub Roztocil for HTTPie

Posted on • Originally published at httpie.io

What’s new in HTTPie 2.6.0

This version of HTTPie introduces numerous improvements to data display and formatting.

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
Enter fullscreen mode Exit fullscreen mode

Prior to HTTPie 2.6.0:

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

����j�����j�����j�����j��
Enter fullscreen mode Exit fullscreen mode

With 2.6.0:

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

維基大典維基大典維基大典維基大典
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8

����j��]Wikipedia�
Enter fullscreen mode Exit fullscreen mode

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

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

維基大典(Wikipedia)
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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."}
Enter fullscreen mode Exit fullscreen mode

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
}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Prior to HTTPie 2.6.0:

{
    "A": 2
}
Enter fullscreen mode Exit fullscreen mode

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

{
    "A": 1,
    "A": 2
}
Enter fullscreen mode Exit fullscreen mode

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 黄海.


Originally published on HTTPie blog.

Top comments (0)

🏗 We built a 100% open source community software called Forem.

You can contribute to the codebase or host your own.