mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
added configurable timeout option to Net::HTTP with spec test
Closes gh-17
This commit is contained in:
parent
71470294dc
commit
30e393142f
2 changed files with 29 additions and 0 deletions
|
@ -41,12 +41,24 @@ module HTTParty
|
|||
end
|
||||
|
||||
private
|
||||
# def http
|
||||
# http = Net::HTTP.new(uri.host, uri.port, options[:http_proxyaddr], options[:http_proxyport])
|
||||
# http.use_ssl = (uri.port == 443)
|
||||
# http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||
# http
|
||||
# end
|
||||
|
||||
def http
|
||||
http = Net::HTTP.new(uri.host, uri.port, options[:http_proxyaddr], options[:http_proxyport])
|
||||
http.use_ssl = (uri.port == 443)
|
||||
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||
if options[:timeout] && options[:timeout].is_a?(Integer)
|
||||
http.open_timeout = options[:timeout]
|
||||
http.read_timeout = options[:timeout]
|
||||
end
|
||||
http
|
||||
end
|
||||
|
||||
|
||||
def body
|
||||
options[:body].is_a?(Hash) ? options[:body].to_params : options[:body]
|
||||
|
|
|
@ -46,6 +46,23 @@ describe HTTParty::Request do
|
|||
@request.send(:setup_raw_request)
|
||||
@request.instance_variable_get(:@raw_request)['authorization'].should_not be_nil
|
||||
end
|
||||
|
||||
it "should change timeout when configured (if an Integer)" do
|
||||
@request.send(:http).open_timeout.should be_nil
|
||||
@request.send(:http).read_timeout.should == 60
|
||||
|
||||
invalid_timeout = "invalid"
|
||||
invalid_timeout.is_a?(Integer).should be_false
|
||||
@request.options[:timeout] = invalid_timeout
|
||||
@request.send(:http).open_timeout.should be_nil
|
||||
@request.send(:http).read_timeout.should == 60
|
||||
|
||||
timeout = 30
|
||||
timeout.is_a?(Integer).should be_true
|
||||
@request.options[:timeout] = timeout
|
||||
@request.send(:http).open_timeout.should == timeout
|
||||
@request.send(:http).read_timeout.should == timeout
|
||||
end
|
||||
end
|
||||
|
||||
describe '#format_from_mimetype' do
|
||||
|
|
Loading…
Add table
Reference in a new issue