2012-11-16 13:59:12 +01:00
|
|
|
require_relative 'accept_type'
|
|
|
|
|
2012-11-08 21:31:24 +01:00
|
|
|
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]\./
|
|
|
|
|
2012-11-16 13:59:12 +01:00
|
|
|
KEY_HTTP_ACCEPT = 'HTTP_ACCEPT'
|
|
|
|
KEY_HTTP_ACCEPT_LANGUAGE = 'HTTP_ACCEPT_LANGUAGE'
|
|
|
|
KEY_HTTP_ACCEPT_ENCODING = 'HTTP_ACCEPT_ENCODING'
|
|
|
|
|
2012-11-14 21:38:57 +01:00
|
|
|
def self.map=(map)
|
2012-11-08 21:31:24 +01:00
|
|
|
@@map = map
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.map
|
|
|
|
@@map ||= {}
|
|
|
|
end
|
|
|
|
|
|
|
|
# create a new accept object
|
2012-11-16 13:59:12 +01:00
|
|
|
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])
|
2012-11-08 21:31:24 +01:00
|
|
|
end
|
|
|
|
|
2012-11-16 13:59:12 +01:00
|
|
|
attr_reader :accept_types
|
|
|
|
attr_reader :accept_language
|
|
|
|
attr_reader :accept_encoding
|
2012-11-08 21:31:24 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|