'Add default headers for every request in httpie
I need to be able to either set in my httpie/config.json file to include some default headers (these are custom headers and not normal ones) to every request that i send from httpie by default (ALWAYS)
ie: headers examples
http "http://poopskiesuprise.com" 'CUSTOM_HEADER:asdf' 'HEADER_TWO:asdf'
always include the 'CUSTOM_HEADER' and 'HEADER_TWO' to every request so i can just do this
http "http://poopskiesuprise.com"
i did not see a good way to do this in the documentation so any help would be great!
Solution 1:[1]
The easiest solution is creating a session with desired headers, and using it on your config.json:
Create a session (for your desired host):
$ http --session ./session.json pie.dev/get X-Custom-Header:value X-Custom-Header2:value2
and then add this to your config (~/.config/httpie/config.json on POSIX):
{
"default_options": [
"--session-read-only=/path/to/session.json"
]
}
and then from now on, every request will add those two headers:
$ http pie.dev/get
{
"args": {},
"headers": {
"X-Custom-Header": "value",
"X-Custom-Header2": "value2"
},
"url": "http://pie.dev/get"
}
Unless you unset them:
$ http pie.dev/get X-Custom-Header:
{
"args": {},
"headers": {
"X-Custom-Header2": "value2"
},
"url": "http://pie.dev/get"
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Batuhan Taskaya |
