Sha256: f248339646177abc050bc4019744feae10e5f8de0bb367ac295e8172672fb135

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

module ApiAuth
  
  module RequestDrivers # :nodoc:
  
    class ActionControllerRequest # :nodoc:
      
      include ApiAuth::Helpers

      def initialize(request)
        @request = request
        @headers = fetch_headers
        true
      end
      
      def set_auth_header(header)
        @request.env["Authorization"] = header
        @headers = fetch_headers
        @request
      end
      
      def fetch_headers
        capitalize_keys @request.env
      end

      def content_type
        value = find_header(%w(CONTENT-TYPE CONTENT_TYPE HTTP_CONTENT_TYPE))
        value.nil? ? "" : value
      end

      def content_md5
        value = find_header(%w(CONTENT-MD5 CONTENT_MD5))
        value.nil? ? "" : value
      end

      def request_uri
        @request.request_uri
      end

      def timestamp
        value = find_header(%w(DATE HTTP_DATE))
        if value.nil?
          value = Time.now.utc.httpdate
          @request.env['DATE'] = value
        end
        value
      end

      def authorization_header
        find_header %w(Authorization AUTHORIZATION HTTP_AUTHORIZATION)
      end

    private

      def find_header(keys)
        keys.map {|key| @headers[key] }.compact.first
      end

    end
    
  end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
api-auth-1.0.0 lib/api_auth/request_drivers/action_controller.rb
api-auth-0.9.3 lib/api_auth/request_drivers/action_controller.rb
api-auth-0.9.2 lib/api_auth/request_drivers/action_controller.rb