summaryrefslogtreecommitdiff
path: root/lib/gitlab_net.rb
diff options
context:
space:
mode:
authorGabor Nagy <mail@aigeruth.hu>2014-06-22 22:45:06 +0200
committerGabor Nagy <mail@aigeruth.hu>2014-06-23 20:52:45 +0200
commit32f1893298bc0108df89de0e543193af20bb0e7c (patch)
tree2fcff9cc992f4560be894f41938573ef3e6bb15e /lib/gitlab_net.rb
parentca425566d0266a1786019153757e283d7d246450 (diff)
downloadgitlab-shell-32f1893298bc0108df89de0e543193af20bb0e7c.tar.gz
Improve coverage.
Diffstat (limited to 'lib/gitlab_net.rb')
-rw-r--r--lib/gitlab_net.rb35
1 files changed, 19 insertions, 16 deletions
diff --git a/lib/gitlab_net.rb b/lib/gitlab_net.rb
index 28971ef..6397106 100644
--- a/lib/gitlab_net.rb
+++ b/lib/gitlab_net.rb
@@ -53,27 +53,30 @@ class GitlabNet
"#{config.gitlab_url}/api/v3/internal"
end
+ def http_client_for(url)
+ Net::HTTP.new(url.host, url.port).tap do |http|
+ if URI::HTTPS === url
+ http.use_ssl = true
+ http.cert_store = cert_store
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE if config.http_settings['self_signed_cert']
+ end
+ end
+ end
+
+ def http_request_for(url)
+ user = config.http_settings['user']
+ password = config.http_settings['password']
+ Net::HTTP::Get.new(url.request_uri).tap { |r| r.basic_auth(user, password) if user && password }
+ end
+
def get(url)
$logger.debug "Performing GET #{url}"
url = URI.parse(url)
- http = Net::HTTP.new(url.host, url.port)
-
- if URI::HTTPS === url
- http.use_ssl = true
- http.cert_store = cert_store
-
- if config.http_settings['self_signed_cert']
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
- end
- end
-
- request = Net::HTTP::Get.new(url.request_uri)
- if config.http_settings['user'] && config.http_settings['password']
- request.basic_auth config.http_settings['user'], config.http_settings['password']
- end
+ http = http_client_for url
+ request = http_request_for url
- http.start {|http| http.request(request) }.tap do |resp|
+ http.start { |http| http.request(request) }.tap do |resp|
if resp.code == "200"
$logger.debug { "Received response #{resp.code} => <#{resp.body}>." }
else