Skip to content

.netrc support for arbitrary headers #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
piranha opened this issue Mar 30, 2025 · 5 comments
Open

.netrc support for arbitrary headers #414

piranha opened this issue Mar 30, 2025 · 5 comments

Comments

@piranha
Copy link

piranha commented Mar 30, 2025

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. :)

@blyxxyz
Copy link
Collaborator

blyxxyz commented Mar 30, 2025

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.

@piranha
Copy link
Author

piranha commented Apr 3, 2025

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. :)

@blyxxyz
Copy link
Collaborator

blyxxyz commented Apr 3, 2025

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

@piranha
Copy link
Author

piranha commented Apr 8, 2025

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. :)

@ducaale
Copy link
Owner

ducaale commented Apr 9, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants