Skip to content

Commit

Permalink
[WIP] Refactors Basic Auth in Faraday. Addresses #1479
Browse files Browse the repository at this point in the history
  • Loading branch information
picandocodigo committed Sep 6, 2021
1 parent bd84d15 commit 9d31fb6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Expand Up @@ -233,7 +233,6 @@ def __convert_to_json(o=nil, options={})
# @api private
def __full_url(host)
url = "#{host[:protocol]}://"
url += "#{CGI.escape(host[:user])}:#{CGI.escape(host[:password])}@" if host[:user]
url += host[:host]
url += ":#{host[:port]}" if host[:port]
url += host[:path] if host[:path]
Expand Down
Expand Up @@ -61,8 +61,12 @@ def perform_request(method, path, params = {}, body = nil, headers = nil, opts =
#
def __build_connection(host, options={}, block=nil)
client = ::Faraday.new(__full_url(host), options, &block)
if host[:user]
auth = Base64.strict_encode64("#{host[:user]}:#{host[:password]}")
(options[:headers] ||= {}).merge!({'Authorization' => "Basic #{auth}"})
end
apply_headers(client, options)
Connections::Connection.new :host => host, :connection => client
Connections::Connection.new(host: host, connection: client)
end

# Returns an array of implementation specific connection errors.
Expand Down

0 comments on commit 9d31fb6

Please sign in to comment.