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 tothe terminal (stderr
), and a progress bar is shown while the response bodyis being saved to a file.
- $ http --download https://github.com/jakubroztocil/httpie/archive/master.tar.gz
- 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 determinesthe output filename (with decreasing priority):
- You can explicitly provide it via
—output, -o
.The file gets overwritten if it already exists(or appended to with—continue, -c
). - The server may specify the filename in the optional
Content-Disposition
response header. Any leading dots are stripped from a server-provided filename. - The last resort HTTPie uses is to generate the filename from a combinationof the request URL and the response
Content-Type
.The initial URL is always used as the basis forthe generated filename — even if there has been one or more redirects.To prevent data loss by overwriting, HTTPie adds a unique numerical suffix to thefilename when necessary (unless specified with—output, -o
).
Piping while downloading
You can also redirect the response body to another program while the responseheaders and progress are still shown in the terminal:
- $ http -d https://github.com/jakubroztocil/httpie/archive/master.tar.gz | tar zxf -
Resuming downloads
If —output, -o
is specified, you can resume a partial download using the—continue, -c
option. This only works with servers that supportRange
requests and 206 Partial Content
responses. If the server doesn'tsupport that, the whole file will simply be downloaded:
- $ http -dco file.zip example.org/file
Other notes
- The
—download
option only changes how the response body is treated. - You can still set custom headers, use sessions,
—verbose, -v
, etc. —download
always implies—follow
(redirects are followed).- HTTPie exits with status code
1
(error) if the body hasn't been fullydownloaded. Accept-Encoding
cannot be set with—download
.