-
Notifications
You must be signed in to change notification settings - Fork 983
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
Support no_proxy via URI::Generic#find_proxy #670
Conversation
This reverts commit dea7726. Conflicts: lib/faraday/options.rb
lib/faraday/connection.rb
Outdated
return uri | ||
else | ||
return nil | ||
end |
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.
Code note: drop the return
keyword on lines 451 and 453 (the if
's the last expression of the method).
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 agree. Moreover, the else
branch is completely redundant. so the if
can be simplified into:
if uri && !uri.empty?
uri = 'http://' + uri if uri !~ /^http/i
uri
end
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 think If the return value of a method is meaningful, return
should be explicitly written. It's easy to read :)
But I think that the consistency of this project should be respected.
I deleted return
dd13327
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'm a big fan of this change.
Hi @authorNari, I can see many tests have been deleted in your PR. |
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 see now, you've found another implementation to support no_proxy
using a Ruby method!
Well, I totally agree we shouldn't reinvent the wheel and if we can use that method then I'm totally happy with it.
I just added a couple of comments to get a better picture.
conn = Faraday::Connection.new | ||
assert_equal conn.proxy_allowed?('http://example.com'), false | ||
end | ||
end |
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.
Please reintroduce all the deleted test as they're covering some important edge-cases.
This can be done without using the proxy_allowed?
method:
- If the test asserts
assert_equal conn.proxy_allowed?('http://example.com'), false
, then you can change it intoassert_nil conn.proxy
- If the test asserts
assert_equal conn.proxy_allowed?('http://prefixedexample.com'), true
than you can change it intoassert_equal 'proxy.com', conn.proxy.host
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.
That make sense. done bbd89c1
uri = 'http://' + uri unless uri.downcase.start_with?('http') | ||
uri | ||
uri = nil | ||
if URI.parse("").respond_to?(:find_proxy) |
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.
According to the documentation, find_proxy
is supported in Ruby 1.9.3 (https://ruby-doc.org/stdlib-1.9.3/libdoc/open-uri/rdoc/URI/Generic.html). Since we dropped the support for older ruby version, I think this method should always be available? Do you get any failing test if you remove this check?
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.
Since we dropped the support for older ruby version, I think this method should always be available?
open-uri
lib has find_proxy
in >= Ruby 1.8.7. This method move to uri/generic
lib in Ruby 2.0.0.
I think any library shouldn't require open-uri
because this library overwrite Kernel#.open.
So this pull request doesn't support no_proxy in Ruby 1.9.3. 😢
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 detailed response @authorNari that makes totally sense.
I have nothing against this as the plan is to move away from Ruby1.9.3 as soon as possible, so this can be a good incentive!
Thank you @authorNari, outstanding work! |
@@ -464,5 +442,14 @@ def set_authorization_header(header_type, *args) | |||
header(*args) | |||
headers[Faraday::Request::Authorization::KEY] = header | |||
end | |||
|
|||
def find_default_proxy | |||
warn 'no_proxy is unsupported' if ENV['no_proxy'] || ENV['NO_PROXY'] |
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.
So no_proxy is unsupported when the url is not given upfront in the initializer, but later on in the request?
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.
You mean when you initialise the connection simply as conn = Faraday.new
?
That is actually true, I missed this detail as it's an unusual way to use it.
This could be easily fixed moving the #find_proxy call on the run_request
or build_request
methods.
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.
Yes, I agree it is a weird way to use it, but it is allowed. The find_proxy method should be moved to when the request is created in build_request
.
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.
Totally agree with you, I'll try to squeeze this small fix in release 0.12.0 👍
Otherwise will be good for 0.12.1 😄
Default proxy value is set via
URI::Generic#find_proxy
if it's defined.Maintenance cost is lower using upstream implementation than a implementation is made by myself.