diff options
| author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-07-04 16:38:05 +0300 |
|---|---|---|
| committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-07-04 16:38:05 +0300 |
| commit | acf1209a92472c83d4200fbbe038416d1209c8e3 (patch) | |
| tree | bb58f6faa2f3eb0da5446bebe44f1f5a7314979c /lib | |
| parent | 456ba294ea9a6f18aae091d91129a1a5dfe0023c (diff) | |
| parent | 80422c666ade9df29e0522b82db7a08f4179089d (diff) | |
| download | gitlab-shell-acf1209a92472c83d4200fbbe038416d1209c8e3.tar.gz | |
Merge branch 'master' of github.com:gitlabhq/gitlab-shell
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/gitlab_net.rb | 35 |
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 |
