Skip to content

Commit

Permalink
Default proxy scheme to http:// if necessary, fixes #1282 (#1283)
Browse files Browse the repository at this point in the history
  • Loading branch information
gurgeous committed May 22, 2021
1 parent 11d793d commit 1f496a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
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

0 comments on commit 1f496a7

Please sign in to comment.