lib/api_auth/headers.rb in api-auth-1.2.0 vs lib/api_auth/headers.rb in api-auth-1.2.1

- old
+ new

@@ -5,40 +5,45 @@ include RequestDrivers def initialize(request) @original_request = request + @request = initialize_request_driver(request) + true + end - case request.class.to_s - when /Net::HTTP/ - @request = NetHttpRequest.new(request) - when /RestClient/ - @request = RestClientRequest.new(request) - when /Curl::Easy/ - @request = CurbRequest.new(request) - when /ActionController::Request/ - @request = ActionControllerRequest.new(request) - when /ActionController::TestRequest/ - if defined?(ActionDispatch) - @request = ActionDispatchRequest.new(request) + def initialize_request_driver(request) + new_request = + case request.class.to_s + when /Net::HTTP/ + NetHttpRequest.new(request) + when /RestClient/ + RestClientRequest.new(request) + when /Curl::Easy/ + CurbRequest.new(request) + when /ActionController::Request/ + ActionControllerRequest.new(request) + when /ActionController::TestRequest/ + if defined?(ActionDispatch) + ActionDispatchRequest.new(request) + else + ActionControllerRequest.new(request) + end + when /ActionDispatch::Request/ + ActionDispatchRequest.new(request) + when /ActionController::CgiRequest/ + ActionControllerRequest.new(request) + when /HTTPI::Request/ + HttpiRequest.new(request) else - @request = ActionControllerRequest.new(request) + nil end - when /ActionDispatch::Request/ - @request = ActionDispatchRequest.new(request) - when /Rack::Request/ - @request = RackRequest.new(request) - when /ActionController::CgiRequest/ - @request = ActionControllerRequest.new(request) - when /HTTPI::Request/ - @request = HttpiRequest.new(request) - when /Sinatra::Request/ - @request = RackRequest.new(request) - else - raise UnknownHTTPRequest, "#{request.class.to_s} is not yet supported." - end - true + + return new_request if new_request + return RackRequest.new(request) if request.kind_of?(Rack::Request) + raise UnknownHTTPRequest, "#{request.class.to_s} is not yet supported." end + private :initialize_request_driver # Returns the request timestamp def timestamp @request.timestamp end