-
Notifications
You must be signed in to change notification settings - Fork 6
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
Set proxies according to the *_PROXY environment variables #22
Comments
Looks good for me! 👍 However, the
This error can of course be easily avoided if prxy = get_proxy(uri)
client.set_proxy prxy
end Thanks! |
Hi @hkalexling @kojix2 |
Long time no see. For some reason, the above code didn't work on Crest. module Crest
class Request
def initialize(
method : Symbol,
url : String,
form = {} of String => String,
**args
)
previous_def
url = URI.parse(@url)
no_proxy = ENV["no_proxy"]? || ENV["NO_PROXY"]?
return if no_proxy && no_proxy.split(",").includes?(url.host)
key = "#{url.scheme}_proxy"
proxy_ = ENV[key.downcase]? || ENV[key.upcase]?
return if proxy_.nil?
uri = URI.parse proxy_
@p_addr = uri.host
@p_port = uri.port
@p_user = uri.user
@p_pass = uri.password
set_proxy!(@p_addr, @p_port, @p_user, @p_pass)
end
end
end However, this workaround breaks as soon as the signature of the |
@kojix2 Which specific piece of code are you referring to? |
The
[protocol]_PROXY
andNO_PROXY
environment variables are commonly used to configure proxies in applications. Wget and Emacs are two examples. Python'srequests
library also respectsHTTP_PROXY
andHTTPS_PROXY
out of the box.It would be great if we could have a helper method like
HTTP::Proxy::Client.use_env
that would do the followingsHTTP::Proxy::Client
objects.HTTP::Client
class in the standard library so that the clients use the appropriate proxies in all requests.Here's an example implementation I used in my project. I will be happy to submit a PR if you think it's a good idea.
The text was updated successfully, but these errors were encountered: