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

Add proxy setting when url_prefix is changed #1276

Merged
merged 2 commits into from Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Expand Up @@ -14,7 +14,7 @@ Metrics/AbcSize:
# Offense count: 5
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 235
Max: 250

# Offense count: 15
# Configuration parameters: IgnoredMethods.
Expand Down
8 changes: 7 additions & 1 deletion lib/faraday/connection.rb
Expand Up @@ -419,6 +419,8 @@ def url_prefix=(url, encoder = nil)
basic_auth user, password
uri.user = uri.password = nil
end

@proxy = proxy_from_env(url) unless @manual_proxy
end

# Sets the path prefix and ensures that it always has a leading
Expand Down Expand Up @@ -577,7 +579,11 @@ def proxy_from_env(url)
case url
when String
uri = Utils.URI(url)
uri = URI.parse("#{uri.scheme}://#{uri.host}").find_proxy
uri = if uri.host.nil?
find_default_proxy
else
URI.parse("#{uri.scheme}://#{uri.host}").find_proxy
end
when URI
uri = url.find_proxy
when nil
Expand Down
8 changes: 8 additions & 0 deletions spec/faraday/connection_spec.rb
Expand Up @@ -442,6 +442,14 @@
end
end

it 'allows when url in no proxy list with url_prefix' do
with_env 'http_proxy' => 'http://proxy.com', 'no_proxy' => 'example.com' do
conn = Faraday::Connection.new
conn.url_prefix = 'http://example.com'
expect(conn.proxy).to be_nil
end
end

it 'allows when prefixed url is not in no proxy list' do
with_env 'http_proxy' => 'http://proxy.com', 'no_proxy' => 'example.com' do
conn = Faraday::Connection.new('http://prefixedexample.com')
Expand Down