Implements the Rack middleware interface.
# File lib/rack/accept/context.rb, line 10 def initialize(app) @app = app @checks = {} @check_headers = [] yield self if block_given? end
Inserts a new Rack::Accept::Request object into the environment before handing the request to the app immediately downstream.
# File lib/rack/accept/context.rb, line 19 def call(env) request = env['rack-accept.request'] ||= Request.new(env) check!(request) unless @checks.empty? @app.call(env) rescue AcceptError response = Response.new response.not_acceptable! response.finish end
Defines the character sets this server is able to serve.
# File lib/rack/accept/context.rb, line 35 def charsets=(charsets) add_check(:charset, charsets) end
Defines the types of encodings this server is able to serve.
# File lib/rack/accept/context.rb, line 40 def encodings=(encodings) add_check(:encoding, encodings) end
Defines the languages this server is able to serve.
# File lib/rack/accept/context.rb, line 45 def languages=(languages) add_check(:language, languages) end
Defines the types of media this server is able to serve.
# File lib/rack/accept/context.rb, line 30 def media_types=(media_types) add_check(:media_type, media_types) end