0
0
zero/lib/zero/request/accept.rb
Gibheer be5cd61bb9 this adds a new accept type
This new class handles various accept strings and makes them available
throught the same API. This way, language and media type feels the same.
2012-11-16 18:13:07 +01:00

37 lines
974 B
Ruby

require_relative 'accept_type'
module Zero
class Request
# encapsulates the accept header to easier work with
# this is partly copied from sinatra
class Accept
MEDIA_TYPE_SEPERATOR = ','
MEDIA_PARAM_SEPERATOR = ';'
MEDIA_QUALITY_REGEX = /q=[01]\./
KEY_HTTP_ACCEPT = 'HTTP_ACCEPT'
KEY_HTTP_ACCEPT_LANGUAGE = 'HTTP_ACCEPT_LANGUAGE'
KEY_HTTP_ACCEPT_ENCODING = 'HTTP_ACCEPT_ENCODING'
def self.map=(map)
@@map = map
end
def self.map
@@map ||= {}
end
# create a new accept object
def initialize(environment)
@accept_types = AcceptType.new(environment[KEY_HTTP_ACCEPT])
@accept_language = AcceptType.new(environment[KEY_HTTP_ACCEPT_LANGUAGE])
@accept_encoding = AcceptType.new(environment[KEY_HTTP_ACCEPT_ENCODING])
end
attr_reader :accept_types
attr_reader :accept_language
attr_reader :accept_encoding
end
end
end