You've already forked httpie-cli
mirror of
https://github.com/httpie/cli.git
synced 2025-12-26 00:31:53 +02:00
Encoding refactoring
* split --response-as into --response-mime and --response-charset * add support for Content-Type charset for requests printed to terminal * add support charset detection for requests printed to terminal without a Content-Type charset * etc.
This commit is contained in:
@@ -1179,6 +1179,8 @@ HTTPie does several things by default in order to make its terminal output easy
|
||||
| `--pretty=format` | Apply formatting |
|
||||
| `--pretty=none` | Disables output processing. Default for redirected output |
|
||||
|
||||
Formatting has the following effects:
|
||||
|
||||
- HTTP headers are sorted by name.
|
||||
- JSON data is indented, sorted by keys, and unicode escapes are converted
|
||||
to the characters they represent.
|
||||
@@ -1259,26 +1261,6 @@ $ http --response-as='text/plain; charset=big5' pie.dev/get
|
||||
|
||||
```bash
|
||||
$ http octodex.github.com/images/original.jpg | convert - -resize 25% - | http example.org/Octocats
|
||||
- Formatting and colors aren’t applied (unless `--pretty` is specified).
|
||||
- Only the response body is printed (unless one of the [output options](#output-options) is set).
|
||||
- Also, binary data isn’t suppressed.
|
||||
|
||||
The reason is to make piping HTTPie’s output to another programs and downloading files work with no extra flags.
|
||||
Most of the time, only the raw response body is of an interest when the output is redirected.
|
||||
|
||||
Download a file:
|
||||
|
||||
```bash
|
||||
$ http pie.dev/image/png > image.png
|
||||
```
|
||||
|
||||
Download an image of an [Octocat](https://octodex.github.com/images/original.jpg), resize it using [ImageMagick](https://imagemagick.org/), and upload it elsewhere:
|
||||
|
||||
```bash
|
||||
$ http octodex.github.com/images/original.jpg | convert - -resize 25% - | http example.org/Octocats
|
||||
```
|
||||
|
||||
Force colorizing and formatting, and show both the request and the response in `less` pager:
|
||||
```
|
||||
|
||||
Force colorizing and formatting, and show both the request and the response in `less` pager:
|
||||
@@ -1320,6 +1302,36 @@ function httpless {
|
||||
TODO:
|
||||
(both request/response)
|
||||
* we look at content-type
|
||||
* else we detect
|
||||
* short texts default to utf8
|
||||
(only response)
|
||||
* --response-charset allows overwriting
|
||||
|
||||
## Download mode
|
||||
|
||||
HTTPie features a download mode in which it acts similarly to `wget`.
|
||||
|
||||
When enabled using the `--download, -d` flag, response headers are printed to the terminal (`stderr`), and a progress bar is shown while the response body is being saved to a file.
|
||||
|
||||
```bash
|
||||
$ http --download https://github.com/httpie/httpie/archive/master.tar.gz
|
||||
```
|
||||
|
||||
```http
|
||||
HTTP/1.1 200 OK
|
||||
Content-Disposition: attachment; filename=httpie-master.tar.gz
|
||||
Content-Length: 257336
|
||||
Content-Type: application/x-gzip
|
||||
|
||||
Downloading 251.30 kB to "httpie-master.tar.gz"
|
||||
Done. 251.30 kB in 2.73862s (91.76 kB/s)
|
||||
```
|
||||
|
||||
### Downloaded filename
|
||||
|
||||
There are three mutually exclusive ways through which HTTPie determines
|
||||
the output filename (with decreasing priority):
|
||||
|
||||
1. You can explicitly provide it via `--output, -o`. The file gets overwritten if it already exists (or appended to with `--continue, -c`).
|
||||
2. The server may specify the filename in the optional `Content-Disposition` response header. Any leading dots are stripped from a server-provided filename.
|
||||
3. The last resort HTTPie uses is to generate the filename from a combination of the request URL and the response `Content-Type`. The initial URL is always used as the basis for the generated filename — even if there has been one or more redirects.
|
||||
|
||||
Reference in New Issue
Block a user