DEV Community

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

Posted on • Originally published at httpie.io

7 2

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.

Agent.ai Challenge image

Congrats to the Agent.ai Challenge Winners 🏆

The wait is over! We are excited to announce the winners of the Agent.ai Challenge.

From meal planners to fundraising automators to comprehensive stock analysts, our team of judges hung out with a lot of agents and had a lot to deliberate over. There were so many creative and innovative submissions, it is always so difficult to select our winners.

Read more →

Top comments (0)

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay