{"id":18728687,"url":"https://github.com/rubyonworld/rack-accept","last_synced_at":"2025-07-14T17:41:06.973Z","repository":{"id":174008045,"uuid":"542159617","full_name":"RubyOnWorld/rack-accept","owner":"RubyOnWorld","description":"Rack::Accept is a suite of tools for Ruby/Rack applications that eases the complexity of building and interpreting the Accept* family of HTTP request headers.","archived":false,"fork":false,"pushed_at":"2022-09-28T00:59:56.000Z","size":122,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-19T20:32:33.179Z","etag":null,"topics":["accept","rack","ract","rails","ruby","suite"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RubyOnWorld.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-09-27T15:32:35.000Z","updated_at":"2022-09-28T03:52:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"6be4b9ca-c096-4af1-bb91-c3472560a1dd","html_url":"https://github.com/RubyOnWorld/rack-accept","commit_stats":null,"previous_names":["rubyonworld/rack-accept"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/RubyOnWorld/rack-accept","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Frack-accept","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Frack-accept/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Frack-accept/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Frack-accept/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RubyOnWorld","download_url":"https://codeload.github.com/RubyOnWorld/rack-accept/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubyOnWorld%2Frack-accept/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260281569,"owners_count":22985627,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["accept","rack","ract","rails","ruby","suite"],"created_at":"2024-11-07T14:23:47.333Z","updated_at":"2025-06-17T03:04:43.787Z","avatar_url":"https://github.com/RubyOnWorld.png","language":"Ruby","readme":"**Rack::Accept** is a suite of tools for Ruby/Rack applications that eases the\ncomplexity of building and interpreting the Accept* family of [HTTP request headers][rfc].\n\nSome features of the library are:\n\n  * Strict adherence to [RFC 2616][rfc], specifically [section 14][rfc-sec14]\n  * Full support for the [Accept][rfc-sec14-1], [Accept-Charset][rfc-sec14-2],\n    [Accept-Encoding][rfc-sec14-3], and [Accept-Language][rfc-sec14-4] HTTP\n    request headers\n  * May be used as [Rack][rack] middleware or standalone\n  * A comprehensive [test suite][test] that covers many edge cases\n\n[rfc]: http://www.w3.org/Protocols/rfc2616/rfc2616.html\n[rfc-sec14]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html\n[rfc-sec14-1]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1\n[rfc-sec14-2]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.2\n[rfc-sec14-3]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3\n[rfc-sec14-4]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4\n[rack]: http://rack.rubyforge.org/\n[test]: http://github.com/mjijackson/rack-accept/tree/master/test/\n\n## Installation\n\n**Using [RubyGems](http://rubygems.org/):**\n\n    $ sudo gem install rack-accept\n\n**From a local copy:**\n\n    $ git clone git://github.com/mjijackson/rack-accept.git\n    $ cd rack-accept\n    $ rake package \u0026\u0026 sudo rake install\n\n## Usage\n\n**Rack::Accept** implements the Rack middleware interface and may be used with any\nRack-based application. Simply insert the `Rack::Accept` module in your Rack\nmiddleware pipeline and access the `Rack::Accept::Request` object in the\n`rack-accept.request` environment key, as in the following example.\n\n```ruby\nrequire 'rack/accept'\n\nuse Rack::Accept\n\napp = lambda do |env|\n  accept = env['rack-accept.request']\n  response = Rack::Response.new\n\n  if accept.media_type?('text/html')\n    response['Content-Type'] = 'text/html'\n    response.write \"\u003cp\u003eHello. You accept text/html!\u003c/p\u003e\"\n  else\n    response['Content-Type'] = 'text/plain'\n    response.write \"Apparently you don't accept text/html. Too bad.\"\n  end\n\n  response.finish\nend\n\nrun app\n```\n\n**Rack::Accept** can also construct automatic [406][406] responses if you set up\nthe types of media, character sets, encoding, or languages your server is able\nto serve ahead of time. If you pass a configuration block to your `use`\nstatement it will yield the `Rack::Accept::Context` object that is used for that\ninvocation.\n\n[406]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.7\n\n```ruby\nrequire 'rack/accept'\n\nuse(Rack::Accept) do |context|\n  # We only ever serve content in English or Japanese from this site, so if\n  # the user doesn't accept either of these we will respond with a 406.\n  context.languages = %w\u003c en jp \u003e\nend\n\napp = ...\n\nrun app\n```\n\n**Note:** _You should think carefully before using Rack::Accept in this way.\nMany user agents are careless about the types of Accept headers they send, and\ndepend on apps not being too picky. Instead of automatically sending a 406, you\nshould probably only send one when absolutely necessary._\n\nAdditionally, **Rack::Accept** may be used outside of a Rack context to provide\nany Ruby app the ability to construct and interpret Accept headers.\n\n```ruby\nrequire 'rack/accept'\n\nmtype = Rack::Accept::MediaType.new\nmtype.qvalues = { 'text/html' =\u003e 1, 'text/*' =\u003e 0.8, '*/*' =\u003e 0.5 }\nmtype.to_s # =\u003e \"Accept: text/html, text/*;q=0.8, */*;q=0.5\"\n\ncset = Rack::Accept::Charset.new('unicode-1-1, iso-8859-5;q=0.8')\ncset.best_of(%w\u003c iso-8859-5 unicode-1-1 \u003e)  # =\u003e \"unicode-1-1\"\ncset.accept?('iso-8859-1')                  # =\u003e true\n```\n\nThe very last line in this example may look like a mistake to someone not\nfamiliar with the intricacies of [the spec][rfc-sec14-3], but it's actually\ncorrect. It just puts emphasis on the convenience of using this library so you\ndon't have to worry about these kinds of details.\n\n## Four-letter Words\n\n  - Spec: [http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html][rfc-sec14]\n  - Code: [http://github.com/mjijackson/rack-accept][code]\n  - Bugs: [http://github.com/mjijackson/rack-accept/issues][bugs]\n  - Docs: [http://mjijackson.github.com/rack-accept][docs]\n\n[code]: http://github.com/mjijackson/rack-accept\n[bugs]: http://github.com/mjijackson/rack-accept/issues\n[docs]: http://mjijackson.github.com/rack-accept\n\n## License\n\nCopyright 2012 Michael Jackson\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nThe software is provided \"as is\", without warranty of any kind, express or\nimplied, including but not limited to the warranties of merchantability,\nfitness for a particular purpose and noninfringement. In no event shall the\nauthors or copyright holders be liable for any claim, damages or other\nliability, whether in an action of contract, tort or otherwise, arising from,\nout of or in connection with the software or the use or other dealings in\nthe software.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubyonworld%2Frack-accept","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubyonworld%2Frack-accept","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubyonworld%2Frack-accept/lists"}