lib/rackbox/rackbox.rb in remi-rackbox-1.1.5 vs lib/rackbox/rackbox.rb in remi-rackbox-1.1.6
- old
+ new
@@ -70,14 +70,35 @@
else
# input should be params, if any
input = RackBox.build_query options[:params]
end
+ # add HTTP BASIC AUTH support
+ #
+ # TODO: DRY this up!
+ #
+ if options[:auth]
+ options[:http_basic_authentication] = options[:auth]
+ options.delete :auth
+ end
+ if options[:basic_auth]
+ options[:http_basic_authentication] = options[:basic_auth]
+ options.delete :basic_auth
+ end
+ if options[:http_basic_authentication]
+ username, password = options[:http_basic_authentication]
+ options.delete :http_basic_authentication
+ require 'base64'
+ # for some reason, nase64 encoding adds a \n
+ encoded_username_and_password = Base64.encode64("#{ username }:#{ password }").sub(/\n$/, '')
+ options['HTTP_AUTHORIZATION'] = "Basic #{ encoded_username_and_password }"
+ end
+
headers = options.dup
headers.delete :data if headers[:data]
headers.delete :params if headers[:params]
headers.delete :method if headers[:method]
-
+
# merge input
headers[:input] = input
puts " requesting #{ options[:method].to_s.upcase } #{ url.inspect } #{ headers.inspect }" if RackBox.verbose
mock_request.send options[:method], url, headers