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 1 commit
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
7 changes: 7 additions & 0 deletions lib/faraday/options/proxy_options.rb
Expand Up @@ -19,6 +19,13 @@ def self.from(value)
value[:uri] = Utils.URI(uri)
end
end

# URIs without a scheme should default to http (like 'example:123'). This
# fixes #1282 and prevents a silent failure in some adapters.
if value && !value[:uri].to_s.include?('://')
value[:uri] = Utils.URI("http://#{value[:uri]}")
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of having this check only in the case when String branch?
That looks like the most common use case, and if a URI or Options object is provided then probably the caller knows what they're doing (leaving the door open to override this automatic fix, if necessary)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea - how about this?


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