xh icon indicating copy to clipboard operation
xh copied to clipboard

.netrc support for arbitrary headers

Open piranha opened this issue 9 months ago • 8 comments

I frequently encounter apis that want something like X-Token: <token> or Authorization: <token> (with no prefix) - would be nice to be able to tell xh to take password as token from .netrc. Not sure how would that look like syntactically. :)

piranha avatar Mar 30 '25 15:03 piranha

Would sessions work?

.netrc is a weird piece of legacy compatibility that I'd rather not extend unless there's some existing standard for it.

blyxxyz avatar Mar 30 '25 15:03 blyxxyz

Eh, sessions are httpie-specific, while I reuse netrc between many tools. But if it doesn't seem right, feel free to close the ticket. :)

piranha avatar Apr 03 '25 06:04 piranha

Do the other tools support headers in netrc files? In that case it might make sense to bring xh in line.

blyxxyz avatar Apr 03 '25 07:04 blyxxyz

ehh couldn't find a tool that does anything like that. I was drawn to xh initially because of that -A bearer support, worked well for a subset of APIs — but obviously when you get used to convenience you end up wanting more. :)

piranha avatar Apr 08 '25 06:04 piranha

Maybe we could introduce header as Auth Type e.g. --auth-type=header --auth=x-api-key:API_KEY? On its own, it wouldn't behave any differently than passing a header directly, but it would support reading it from .netrc

$ cat ~/.netrc
machine httpbin.org password x-api-key:12345

$ xh --offline -A header httpbin.org/get
GET /get HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate, br, zstd
X-Api-Key: 12345 # <------- header read from .netrc
Connection: keep-alive
Host: httpbin.org
User-Agent: xh/0.23.1

With that being said, this might be stretching .netrc beyond its intended use. Not to mention that that we would be introducing an auth type that likely wouldn't be useful in most cases.

ducaale avatar Apr 09 '25 22:04 ducaale

Yeah, just having a little command line script to read from .netrc is more composable, like xh httpbin.org/get x-api-key:$(netrc httpbin.org). Only the fact that domain is repeated sucks somewhat. :)

piranha avatar Apr 17 '25 20:04 piranha