Skip to content
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

Merged
merged 4 commits into from
Mar 15, 2017

Conversation

authorNari
Copy link
Contributor

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.

return uri
else
return nil
end
Copy link
Member

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

Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Member

@olleolleolle olleolleolle left a 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.

@iMacTia
Copy link
Member

iMacTia commented Mar 3, 2017

Hi @authorNari,

I can see many tests have been deleted in your PR.
Can I ask you why?

@authorNari
Copy link
Contributor Author

Hi @iMacTia

511a5b4 is reverted on this pull request so these tests are deleted.
These tests are depends on proxy_allowed? method.

Copy link
Member

@iMacTia iMacTia left a 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
Copy link
Member

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 into assert_nil conn.proxy
  • If the test asserts assert_equal conn.proxy_allowed?('http://prefixedexample.com'), true than you can change it into assert_equal 'proxy.com', conn.proxy.host

Copy link
Contributor Author

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)
Copy link
Member

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?

Copy link
Contributor Author

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. 😢

Copy link
Member

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!

@iMacTia
Copy link
Member

iMacTia commented Mar 15, 2017

Thank you @authorNari, outstanding work!
I'm grateful we could delegate to Ruby the management of the proxy/no_proxy ENV variables check.
Apologies if it took me some time to review and thanks again for the valuable contribution.

@iMacTia iMacTia merged commit 3268aca into lostisland:master Mar 15, 2017
@iMacTia iMacTia added this to the v0.12.0 milestone Mar 15, 2017
@@ -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']
Copy link
Contributor

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?

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Member

@iMacTia iMacTia Mar 22, 2017

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 😄

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

Successfully merging this pull request may close these issues.

4 participants