You've already forked httpie-cli
mirror of
https://github.com/httpie/cli.git
synced 2026-04-26 20:02:11 +02:00
Allow to overwrite the response Content-Type from options (#1134)
* Allow to override the response `Content-Type` from options * Apply suggestions from code review Co-authored-by: Jakub Roztocil <jakub@roztocil.co> * Rename the option from `--response.content-type` to `--response-as` * Update CHANGELOG.md Co-authored-by: Jakub Roztocil <jakub@roztocil.co>
This commit is contained in:
committed by
GitHub
parent
8f8851f1db
commit
9c89c703ae
+21
-8
@@ -1214,14 +1214,15 @@ You can further control the applied formatting via the more granular [format opt
|
||||
|
||||
This is something you will typically store as one of the default options in your [config](#config) file.
|
||||
|
||||
|
||||
Binary data is suppressed for terminal output, which makes it safe to perform requests to URLs that send back binary data.
|
||||
Binary data is also suppressed in redirected but prettified output.
|
||||
The connection is closed as soon as we know that the response body is binary,
|
||||
|
||||
```bash
|
||||
$ http pie.dev/bytes/2000
|
||||
```
|
||||
#### Response `Content-Type`
|
||||
|
||||
The `--response-as=value` option is a shortcut for `--format-options response.as:value`,
|
||||
and it allows you to override the response `Content-Type` sent by the server.
|
||||
That makes it possible for HTTPie to pretty-print the response even when the server specifies the type incorrectly.
|
||||
|
||||
For example, the following request will force the response to be treated as XML:
|
||||
|
||||
```bash
|
||||
$ http --response-as=application/xml pie.dev/get
|
||||
```
|
||||
|
||||
@@ -1236,6 +1237,18 @@ sorting-related format options (currently it means JSON keys and headers):
|
||||
```
|
||||
|
||||
You will nearly instantly see something like this:
|
||||
|
||||
```http
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: application/octet-stream
|
||||
|
||||
```
|
||||
|
||||
### Redirected output
|
||||
|
||||
HTTPie uses a different set of defaults for redirected output than for [terminal output](#terminal-output).
|
||||
The differences being:
|
||||
|
||||
- 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.
|
||||
|
||||
Reference in New Issue
Block a user