1
0
Fork 0
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:
Mark 2009-05-01 16:51:44 -06:00 committed by Sandro Turriate
parent 71470294dc
commit 30e393142f
2 changed files with 29 additions and 0 deletions

View file

@ -41,13 +41,25 @@ 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]
end

View file

@ -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