summaryrefslogtreecommitdiff
path: root/lib/nickserver/adapters/http.rb
diff options
context:
space:
mode:
authorazul <azul@riseup.net>2016-12-02 11:25:35 +0000
committerazul <azul@riseup.net>2016-12-02 11:25:35 +0000
commit8bfd27e0c851e9786110be4e6485635f769d853f (patch)
treeaed9cc67f5711352e86d8314a4718c777a23cc43 /lib/nickserver/adapters/http.rb
parent244d8a4702f98619078c0e09e485d7e1944e5013 (diff)
parent0aa101524270c0c398fe17c287d51927f810e499 (diff)
Merge branch 'bugfix/couch-auth' into 'master'
bugfix: use user:password@ prefix in http basic auth See merge request !9
Diffstat (limited to 'lib/nickserver/adapters/http.rb')
-rw-r--r--lib/nickserver/adapters/http.rb24
1 files changed, 21 insertions, 3 deletions
diff --git a/lib/nickserver/adapters/http.rb b/lib/nickserver/adapters/http.rb
index b0ba728..636aceb 100644
--- a/lib/nickserver/adapters/http.rb
+++ b/lib/nickserver/adapters/http.rb
@@ -6,12 +6,30 @@ module Nickserver::Adapters
class Http
def get(url, options = {})
- response = HTTP.get url,
- params: options[:query],
- ssl_context: ctx
+ url = HTTP::URI.parse url.to_s
+ response = get_with_auth url, params: options[:query]
return response.code, response.to_s
end
+ protected
+
+ def get_with_auth(url, options)
+ options = default_options.merge options
+ http_with_basic_auth(url).get url, options
+ end
+
+ def http_with_basic_auth(url)
+ if url.password && (url.password != '')
+ HTTP.basic_auth(user: url.user, pass: url.password)
+ else
+ HTTP
+ end
+ end
+
+ def default_options
+ { ssl_context: ctx }
+ end
+
def ctx
OpenSSL::SSL::SSLContext.new.tap do |ctx|
ctx.ca_file = Nickserver::Config.hkp_ca_file