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 support for setting Ruby Net::HTTP read_timeout option separately #1003

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/faraday/adapter/net_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ def configure_request(http, req)
end
end
http.open_timeout = req[:open_timeout] if req[:open_timeout]
http.read_timeout = req[:read_timeout] if req[:read_timeout]

if req[:write_timeout] && http.respond_to?(:write_timeout=)
http.write_timeout = req[:write_timeout]
end
Expand Down
5 changes: 3 additions & 2 deletions lib/faraday/options/request_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
module Faraday
# RequestOptions contains the configurable properties for a Faraday request.
class RequestOptions < Options.new(:params_encoder, :proxy, :bind,
:timeout, :open_timeout, :write_timeout,
:boundary, :oauth, :context, :on_data)
:timeout, :open_timeout, :read_timeout,
:write_timeout, :boundary, :oauth,
:context, :on_data)

def []=(key, value)
if key && key.to_sym == :proxy
Expand Down
10 changes: 10 additions & 0 deletions spec/faraday/adapter/net_http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@

expect(http.write_timeout).to eq(10) if http.respond_to?(:write_timeout=)
end
it 'supports open_timeout' do
adapter.send(:configure_request, http, open_timeout: 10)

expect(http.open_timeout).to eq(10)
end
it 'supports read_timeout' do
adapter.send(:configure_request, http, read_timeout: 10)

expect(http.read_timeout).to eq(10)
end

context 'with https url' do
let(:url) { URI('https://example.com') }
Expand Down