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

default proxy to http:// if necessary, fixes #1282 #1283

Merged
merged 3 commits into from May 22, 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
4 changes: 4 additions & 0 deletions lib/faraday/options/proxy_options.rb
Expand Up @@ -11,6 +11,9 @@ class ProxyOptions < Options.new(:uri, :user, :password)
def self.from(value)
case value
when String
# URIs without a scheme should default to http (like 'example:123').
# This fixes #1282 and prevents a silent failure in some adapters.
value = "http://#{value}" unless value.include?('://')
value = { uri: Utils.URI(value) }
when URI
value = { uri: value }
Expand All @@ -19,6 +22,7 @@ def self.from(value)
value[:uri] = Utils.URI(uri)
end
end

super(value)
end

Expand Down
7 changes: 7 additions & 0 deletions spec/faraday/options/proxy_options_spec.rb
Expand Up @@ -14,6 +14,13 @@
expect(options.inspect).to match('#<Faraday::ProxyOptions uri=')
end

it 'defaults to http' do
options = Faraday::ProxyOptions.from 'example.org'
expect(options.port).to eq(80)
expect(options.host).to eq('example.org')
expect(options.scheme).to eq('http')
end

it 'works with nil' do
options = Faraday::ProxyOptions.from nil
expect(options).to be_a_kind_of(Faraday::ProxyOptions)
Expand Down