summaryrefslogtreecommitdiff
path: root/lib/gitlab_net.rb
diff options
context:
space:
mode:
authorJacob Vosmaer <contact@jacobvosmaer.nl>2016-02-09 17:04:29 +0100
committerJacob Vosmaer <contact@jacobvosmaer.nl>2016-02-09 17:04:29 +0100
commite07469ff7bf3b65908fa2aeb572b56974133b25a (patch)
tree434f3dc2a3838140b25fd3b22af9623cec5c990f /lib/gitlab_net.rb
parent82b3a4e8f70692ec679d880628fdb0f5844d42b9 (diff)
downloadgitlab-shell-e07469ff7bf3b65908fa2aeb572b56974133b25a.tar.gz
Use an HTTP timeout of 5 minutes by default
Diffstat (limited to 'lib/gitlab_net.rb')
-rw-r--r--lib/gitlab_net.rb17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/gitlab_net.rb b/lib/gitlab_net.rb
index 6f47938..5d0148e 100644
--- a/lib/gitlab_net.rb
+++ b/lib/gitlab_net.rb
@@ -10,6 +10,9 @@ require_relative 'httpunix'
class GitlabNet
class ApiUnreachableError < StandardError; end
+ CHECK_TIMEOUT = 5
+ READ_TIMEOUT = 300
+
def check_access(cmd, repo, actor, changes)
project_name = repo.gsub("'", "")
project_name = project_name.gsub(/\.git\Z/, "")
@@ -50,7 +53,7 @@ class GitlabNet
end
def check
- get("#{host}/check")
+ get("#{host}/check", read_timeout: CHECK_TIMEOUT)
end
protected
@@ -63,13 +66,15 @@ class GitlabNet
"#{config.gitlab_url}/api/v3/internal"
end
- def http_client_for(uri)
+ def http_client_for(uri, options={})
if uri.is_a?(URI::HTTPUNIX)
http = Net::HTTPUNIX.new(uri.hostname)
else
http = Net::HTTP.new(uri.host, uri.port)
end
+ http.read_timeout = options[:read_timeout] || READ_TIMEOUT
+
if uri.is_a?(URI::HTTPS)
http.use_ssl = true
http.cert_store = cert_store
@@ -92,12 +97,12 @@ class GitlabNet
request
end
- def request(method, url, params = {})
+ def request(method, url, params = {}, options={})
$logger.debug "Performing #{method.to_s.upcase} #{url}"
uri = URI.parse(url)
- http = http_client_for(uri)
+ http = http_client_for(uri, options)
request = http_request_for(method, uri, params)
begin
@@ -116,8 +121,8 @@ class GitlabNet
response
end
- def get(url)
- request(:get, url)
+ def get(url, options={})
+ request(:get, url, {}, options)
end
def post(url, params)