Rack::Accept ============ rack-accept is a suite of tools for Rack/Ruby applications that eases the complexity of reading and writing Accept, Accept-Charset, Accept-Encoding, and Accept-Language HTTP request headers. Installation ------------ Using RubyGems: $ sudo gem install rack-accept From a local copy: $ git clone git://github.com/mjijackson/rack-accept.git $ rake package && sudo rake install Usage ----- rack-accept implements the Rack middleware interface and may be used with any Rack-based application. Simply insert the Rack::Accept module in your Rack middleware pipeline and access the Rack::Accept::Request object in the "rack-accept.request" environment key, as in the following example: require 'rack/accept' use Rack::Accept app = lambda {|env| accept = env['rack-accept.request'] response = Rack::Response.new if accept.media_type?('text/html') response['Content-Type'] = 'text/html' response.write "
Hello. You accept text/html!
" else response['Content-Type'] = 'text/plain' response.write "Apparently you don't accept text/html. Too bad." end response.finish } run app License ------- Copyright 2010 Michael J. I. Jackson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.