Sha256: eb0ec78723a3524f626794bf247d56f193fc4c22092e5148c8ab7b657e1dac92

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 KB

Contents

module ApiAuth

  module RequestDrivers # :nodoc:

    class CurbRequest # :nodoc:

      include ApiAuth::Helpers

      def initialize(request)
        @request = request
        @headers = fetch_headers
        true
      end

      def set_auth_header(header)
        @request.headers.merge!({ "Authorization" => header })
        @headers = fetch_headers
        @request
      end

      def populate_content_md5
        nil #doesn't appear to be possible
      end

      def md5_mismatch?
        false
      end

      def fetch_headers
        capitalize_keys @request.headers
      end

      def http_method
        nil # not possible to get the method at this layer
      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.url
      end

      def set_date
        @request.headers.merge!({ "DATE" => Time.now.utc.httpdate })
      end

      def timestamp
        value = find_header(%w(DATE HTTP_DATE))
        value.nil? ? "" : 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

1 entries across 1 versions & 1 rubygems

Version Path
api-auth-1.4.0 lib/api_auth/request_drivers/curb.rb