set timeouts for CanvasHttp requests
fixes CNVS-24680 Change-Id: I8317983ea8f735aa5eb2d99bb7b5750e2727d03b Reviewed-on: https://gerrit.instructure.com/66714 Tested-by: Jenkins Reviewed-by: Simon Williams <simon@instructure.com> Product-Review: Cody Cutrer <cody@instructure.com> QA-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
parent
9bea407c80
commit
3e61b9bdd4
|
@ -0,0 +1,2 @@
|
|||
CanvasHttp.open_timeout = -> { Setting.get('http_open_timeout', 5).to_f }
|
||||
CanvasHttp.read_timeout = -> { Setting.get('http_read_timeout', 30).to_f }
|
|
@ -68,9 +68,23 @@ module CanvasHttp
|
|||
def self.connection_for_uri(uri)
|
||||
http = Net::HTTP.new(uri.host, uri.port)
|
||||
http.use_ssl = (uri.scheme == 'https')
|
||||
http.ssl_timeout = http.open_timeout = open_timeout
|
||||
http.read_timeout = read_timeout
|
||||
return http
|
||||
end
|
||||
|
||||
def self.open_timeout
|
||||
@open_timeout.respond_to?(:call) ? @open_timeout.call : @open_timeout || 5
|
||||
end
|
||||
|
||||
def self.read_timeout
|
||||
@read_timeout.respond_to?(:call) ? @read_timeout.call : @read_timeout || 30
|
||||
end
|
||||
|
||||
class << self
|
||||
attr_writer :open_timeout, :read_timeout
|
||||
end
|
||||
|
||||
# returns a tempfile with a filename based on the uri (same extension, if
|
||||
# there was an extension)
|
||||
def self.tempfile_for_uri(uri)
|
||||
|
|
|
@ -50,6 +50,9 @@ describe "CanvasHttp" do
|
|||
expect(http).to receive(:use_ssl=).with(true)
|
||||
expect(http).to receive(:verify_mode=).with(OpenSSL::SSL::VERIFY_NONE)
|
||||
expect(http).to receive(:request).and_yield(double(body: 'Hello SSL'))
|
||||
expect(http).to receive(:open_timeout=).with(5)
|
||||
expect(http).to receive(:ssl_timeout=).with(5)
|
||||
expect(http).to receive(:read_timeout=).with(30)
|
||||
|
||||
CanvasHttp.get("https://www.example.com/a/b").body.should == "Hello SSL"
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue