-
Notifications
You must be signed in to change notification settings - Fork 102
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
Add --noproxy argument to ignore proxy for hosts or IP addresses. #410
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
For the name, maybe --disable-proxy-for
? Bit of a mouthful though.
/// - A '*' matches all hosts, and effectively disables proxies altogether. | ||
/// - IP addresses are allowed, as are subnets (in CIDR notation, i.e.: '127.0.0.0/8'). | ||
/// - Any other entry in the list is assumed to be a hostname. | ||
#[clap(long, value_name = "no-proxy-list", value_delimiter = ',')] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this trim spaces? I see google.com, 192.168.1.0/24
as an example in the reqwest docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would appear that it does! See: https://docs.rs/reqwest/latest/src/reqwest/proxy.rs.html#474
I'll add a test to verify that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant whether clap's value_delimiter
trims spaces, so our logic matches up with reqwest's
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, snap, yeah, great question! I'll definitely test it then! I was toying with the idea to keep the list in a String
so I could offload the full parsing to reqwest. I might have to revisit that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a few tests that should demonstrate that:
- whitespace in
--disable-proxy-for
is trimmed - any request to a host not specified in
--disable-proxy-for
still gets proxied
src/cli.rs
Outdated
/// Comma-separated list of hosts for which not to use a proxy, if one is specified. | ||
/// | ||
/// - A '*' matches all hosts, and effectively disables proxies altogether. | ||
/// - IP addresses are allowed, as are subnets (in CIDR notation, i.e.: '127.0.0.0/8'). | ||
/// - Any other entry in the list is assumed to be a hostname. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you mention the environment variable here like we do for --proxy
?
src/cli.rs
Outdated
if noproxy.contains(&"*".to_string()) { | ||
// reqwest's NoProxy wildcard doesn't apply to IP addresses, while curl's does | ||
noproxy_comma_delimited.push_str(",0.0.0.0/0,::/0"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this creates a difference between the CLI flag and the environment variable. To be fully correct we may have to reimplement the env variable handling...
HTTPie (presumably via requests
) also follows the curl behavior here.
I suspect this is a mistake in reqwest
, since the original PR that added *
describes it as "effectively disabling use of the proxy". Maybe we can file an issue and/or PR there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can file an issue and/or PR there?
That's an excellent idea. I had considered doing that, but got tempted (nerdsniped, perhaps?) to work around it, which, in retrospect, I shouldn't have. I hadn't even considered (or indeed known about? the environment variable reqwest reads.
Speaking of which, NoProxy::from_string
's docs imply that it ignores its argument if the NO_PROXY
/no_proxy
environment variable is set, which doesn't actually seem to be the case from a cursory look at the code. Maybe I ought to mention that as well in the issue I'll open.
Thanks for pushing back here 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue filed here: seanmonstar/reqwest#2579
tests/cli.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I think these tests would pass even if all --noproxy
did was disable all proxies all the time. Can you add tests to check cases in which the pattern doesn't cover the URL and so the proxy does get used?
Some of the ideas I had about the name:
Is there some "guideline"/design principle that's used to name flags? I originally added support for |
Most of the flags are inherited from HTTPie, so we don't have a lot of experience coming up with names unfortunately.
Uhh, I'll use an LLM. I'll pretend these options already exist and ask it what they do and read what it hallucinates. That hopefully gets close to the intuition of real users. First I ask
And it doesn't get the syntax quite right but it correctly guesses what the option is for. Then I ask
And it gives examples where it doesn't take an argument,
I also asked it
And it came up with this, which is pretty interesting: We have the But maybe it's a little too cute, and I'd first want to check if the syntax for the Finally I asked it
and it hallucinated Take all of this with a grain of salt of course. |
@blyxxyz Can you take a look at the latest changes? And maybe also see if there's anything you'd like to add to the issue I raised at seanmonstar/reqwest#2579 ? |
This is getting into software archeology, but it kinda looks like httpie's syntax for proxies is a direct mapping of the underlying requests library: https://docs.python-requests.org/en/latest/user/advanced/#proxies I do like the idea of adding something like |
I saw #296 as a good first issue and thought I'd have a go at it.
A few things to note:
--noproxy
), as that seems to be what you were aiming for. This could potentially be confusing for users, as it's similar to--no-proxy
, which undoes any--proxy
arguments.NoProxy
's applies a wildcard (*
) only to hostnames, not IP addresses. curl does both. So there's a little workaround to implicitly add IPv4 and IPv6 full ranges (respectively0.0.0.0/0
and::/0
).lo
has that by default), and for hostnames, I thought I could use--resolve
, but that turns the hostname into an IP address, so the hostname never reaches reqwest. If needed, I can take a closer look to see if I can add these tests.