class Ocular::Inputs::HTTP::Input::Request

Constants

HEADER_PARAM
HEADER_VALUE_WITH_PARAMS

Public Instance Methods

accept() click to toggle source

Returns an array of acceptable media types for the response

# File lib/ocular/inputs/http_input.rb, line 109
def accept
    @env['sinatra.accept'] ||= begin
    if @env.include? 'HTTP_ACCEPT' and @env['HTTP_ACCEPT'].to_s != ''
        @env['HTTP_ACCEPT'].to_s.scan(HEADER_VALUE_WITH_PARAMS).
            map! { |e| AcceptEntry.new(e) }.sort
        else
            [AcceptEntry.new('*/*')]
        end
    end
end
accept?(type) click to toggle source
# File lib/ocular/inputs/http_input.rb, line 120
def accept?(type)
    preferred_type(type).to_s.include?(type)
end
forwarded?() click to toggle source
# File lib/ocular/inputs/http_input.rb, line 137
def forwarded?
    @env.include? "HTTP_X_FORWARDED_HOST"
end
idempotent?() click to toggle source
# File lib/ocular/inputs/http_input.rb, line 145
def idempotent?
    safe? or put? or delete? or link? or unlink?
end
preferred_type(*types) click to toggle source
# File lib/ocular/inputs/http_input.rb, line 124
def preferred_type(*types)
    accepts = accept # just evaluate once
    return accepts.first if types.empty?
    types.flatten!
    return types.first if accepts.empty?
    accepts.detect do |pattern|
        type = types.detect { |t| File.fnmatch(pattern, t) }
        return type if type
    end
end
safe?() click to toggle source
# File lib/ocular/inputs/http_input.rb, line 141
def safe?
    get? or head? or options? or trace?
end