Skip to content

Commit a15fd6f

Browse files
BoboTiGjkbrzt
andauthored
Add --response=mime and --response=charset docs (#1179)
* Add the "display encoding" section in the docs * Remove repetition * `--response=mime` / `--response=charset` docs * Cleanup * Cleanup * Cleanup Co-authored-by: Jakub Roztocil <[email protected]>
1 parent 19691bb commit a15fd6f

File tree

1 file changed

+11
-37
lines changed

1 file changed

+11
-37
lines changed

docs/README.md

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,10 +1425,8 @@ HTTPie does several things by default in order to make its terminal output easy
14251425
14261426
### Colors and formatting
14271427
1428-
<!-- TODO: mention body colors/formatting are based on content-type + --response-mime (heuristics for JSON content-type) -->
1429-
14301428
Syntax highlighting is applied to HTTP headers and bodies (where it makes sense).
1431-
You can choose your preferred color scheme via the `--style` option if you don’t like the default one.
1429+
You can choose your preferred color scheme via the --style option if you don’t like the default one.
14321430
There are dozens of styles available, here are just a few notable ones:
14331431
14341432
| Style | Description |
@@ -1448,6 +1446,12 @@ Use one of these options to control output processing:
14481446
| `--pretty=format` | Apply formatting |
14491447
| `--pretty=none` | Disables output processing. Default for redirected output |
14501448
1449+
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 manually overwrite the mime type for a response with `--response-mime`:
1450+
1451+
```bash
1452+
$ http --response-mime=text/yaml pie.dev/get
1453+
```
1454+
14511455
Formatting has the following effects:
14521456
14531457
- HTTP headers are sorted by name.
@@ -1484,29 +1488,6 @@ sorting-related format options (currently it means JSON keys and headers):
14841488
14851489
This is something you will typically store as one of the default options in your [config](#config) file.
14861490
1487-
### Response `Content-Type`
1488-
1489-
The `--response-as=value` option allows you to override the response `Content-Type` sent by the server.
1490-
That makes it possible for HTTPie to print the response even when the server specifies the type incorrectly.
1491-
1492-
For example, the following request will force the response to be treated as XML:
1493-
1494-
```bash
1495-
$ http --response-as=application/xml pie.dev/get
1496-
```
1497-
1498-
And the following requests will force the response to use the [big5](https://docs.python.org/3/library/codecs.html#standard-encodings) encoding:
1499-
1500-
```bash
1501-
$ http --response-as='charset=big5' pie.dev/get
1502-
```
1503-
1504-
```bash
1505-
$ http --response-as='text/plain; charset=big5' pie.dev/get
1506-
```
1507-
1508-
Given the encoding is not sent by the server, HTTPie will auto-detect it.
1509-
15101491
### Redirected output
15111492
15121493
HTTPie uses a different set of defaults for redirected output than for [terminal output](#terminal-output).
@@ -1569,20 +1550,13 @@ Content-Type: application/octet-stream
15691550
+-----------------------------------------+
15701551
```
15711552
1572-
<!--
15731553
### Display encoding
15741554
1575-
TODO:
1576-
(both request/response)
1577-
1578-
- we look at content-type
1579-
- else we detect
1580-
- short texts default to utf8
1555+
HTTPie tries to do its best to decode message bodies when printing them to the terminal correctly. It uses the encoding specified in the `Content-Type` `charset` attribute. If a message doesn’t define its charset, we auto-detect it. For very short messages (1–32B), where auto-detection would be unreliable, we default to UTF-8. For cases when the response encoding is still incorrect, you can manually overwrite the response charset with `--response-charset`:
15811556
1582-
(only response)
1583-
1584-
- --response-charset allows overwriting
1585-
- -->
1557+
```bash
1558+
$ http --response-charset=big5 pie.dev/get
1559+
```
15861560
15871561
## Download mode
15881562

0 commit comments

Comments
 (0)