1 = rdoc-image:contrib/logo.webp
3 {<img src="https://github.com/rack/rack/workflows/Development/badge.svg" alt="GitHub Actions status" />}[https://github.com/rack/rack/actions?query=workflow%3ADevelopment]
4 {<img src="https://badge.fury.io/rb/rack.svg" alt="Gem Version" />}[http://badge.fury.io/rb/rack]
5 {<img src="http://inch-ci.org/github/rack/rack.svg?branch=master" alt="Inline docs" />}[http://inch-ci.org/github/rack/rack]
7 \Rack provides a minimal, modular, and adaptable interface for developing
8 web applications in Ruby. By wrapping HTTP requests and responses in
9 the simplest way possible, it unifies and distills the API for web
10 servers, web frameworks, and software in between (the so-called
11 middleware) into a single method call.
13 The exact details of this are described in the {\Rack specification}[link:SPEC.rdoc],
14 which all \Rack applications should conform to.
16 == Supported web servers
18 The included *handlers* can connect these web servers to \Rack:
20 * WEBrick[https://github.com/ruby/webrick]
23 These web servers include \Rack handlers in their distributions:
25 * Agoo[https://github.com/ohler55/agoo]
26 * Falcon[https://github.com/socketry/falcon]
27 * Iodine[https://github.com/boazsegev/iodine]
28 * {NGINX Unit}[https://unit.nginx.org/]
29 * {Phusion Passenger}[https://www.phusionpassenger.com/] (which is mod_rack for Apache and for nginx)
30 * Puma[https://puma.io/]
31 * Thin[https://rubygems.org/gems/thin]
32 * Unicorn[https://yhbt.net/unicorn/]
33 * uWSGI[https://uwsgi-docs.readthedocs.io/en/latest/]
34 * Lamby[https://lamby.custominktech.com] (for AWS Lambda)
36 Any valid \Rack app will run the same on all these handlers, without
39 == Supported web frameworks
41 These frameworks and many others support the \Rack API:
43 * Camping[http://www.ruby-camping.com/]
44 * Coset[http://leahneukirchen.org/repos/coset/]
45 * Hanami[https://hanamirb.org/]
46 * Padrino[http://padrinorb.com/]
47 * Ramaze[http://ramaze.net/]
48 * Roda[https://github.com/jeremyevans/roda]
49 * {Ruby on Rails}[https://rubyonrails.org/]
50 * Rum[https://github.com/leahneukirchen/rum]
51 * Sinatra[http://sinatrarb.com/]
52 * Utopia[https://github.com/socketry/utopia]
53 * WABuR[https://github.com/ohler55/wabur]
55 == Available middleware shipped with \Rack
57 Between the server and the framework, \Rack can be customized to your
58 applications needs using middleware. \Rack itself ships with the following
61 * Rack::Chunked, for streaming responses using chunked encoding.
62 * Rack::CommonLogger, for creating Apache-style logfiles.
63 * Rack::ConditionalGet, for returning not modified responses when the response
65 * Rack::Config, for modifying the environment before processing the request.
66 * Rack::ContentLength, for setting content-length header based on body size.
67 * Rack::ContentType, for setting default content-type header for responses.
68 * Rack::Deflater, for compressing responses with gzip.
69 * Rack::ETag, for setting ETag header on string bodies.
70 * Rack::Events, for providing easy hooks when a request is received
71 and when the response is sent.
72 * Rack::Files, for serving static files.
73 * Rack::Head, for returning an empty body for HEAD requests.
74 * Rack::Lint, for checking conformance to the \Rack API.
75 * Rack::Lock, for serializing requests using a mutex.
76 * Rack::Logger, for setting a logger to handle logging errors.
77 * Rack::MethodOverride, for modifying the request method based on a submitted
79 * Rack::Recursive, for including data from other paths in the application,
80 and for performing internal redirects.
81 * Rack::Reloader, for reloading files if they have been modified.
82 * Rack::Runtime, for including a response header with the time taken to
84 * Rack::Sendfile, for working with web servers that can use optimized
85 file serving for file system paths.
86 * Rack::ShowException, for catching unhandled exceptions and
87 presenting them in a nice and helpful way with clickable backtrace.
88 * Rack::ShowStatus, for using nice error pages for empty client error
90 * Rack::Static, for more configurable serving of static files.
91 * Rack::TempfileReaper, for removing temporary files creating during a
94 All these components use the same interface, which is described in
95 detail in the \Rack specification. These optional components can be
96 used in any way you wish.
100 If you want to develop outside of existing frameworks, implement your
101 own ones, or develop middleware, \Rack provides many helpers to create
102 \Rack applications quickly and without doing the same web stuff all
105 * Rack::Request, which also provides query string parsing and
107 * Rack::Response, for convenient generation of HTTP replies and
109 * Rack::MockRequest and Rack::MockResponse for efficient and quick
110 testing of \Rack application without real HTTP round-trips.
111 * Rack::Cascade, for trying additional \Rack applications if an
112 application returns a not found or method not supported response.
113 * Rack::Directory, for serving files under a given directory, with
115 * Rack::MediaType, for parsing content-type headers.
116 * Rack::Mime, for determining content-type based on file extension.
117 * Rack::RewindableInput, for making any IO object rewindable, using
118 a temporary file buffer.
119 * Rack::URLMap, to route to multiple applications inside the same process.
123 The plethora of useful middleware created the need for a project that
124 collects fresh \Rack middleware. rack-contrib includes a variety of
125 add-on components for \Rack and it is easy to contribute new modules.
127 * https://github.com/rack/rack-contrib
131 rackup is a useful tool for running \Rack applications, which uses the
132 Rack::Builder DSL to configure middleware and build up applications
135 rackup automatically figures out the environment it is run in, and
136 runs your application as FastCGI, CGI, or WEBrick---all from the
143 Either with the embedded WEBrick starter:
145 ruby -Ilib lib/rack/lobster.rb
149 bin/rackup -Ilib example/lobster.ru
151 By default, the lobster is found at http://localhost:9292.
153 == Installing with RubyGems
155 A Gem of \Rack is available at {rubygems.org}[https://rubygems.org/gems/rack]. You can install it with:
161 You should require the library:
165 \Rack uses autoload to automatically load other files \Rack ships with on demand,
166 so you should not need require paths under +rack+. If you require paths under
167 +rack+ without requiring +rack+ itself, things may not work correctly.
171 Several parameters can be modified on Rack::Utils to configure \Rack behaviour.
175 Rack::Utils.param_depth_limit = 3
178 === param_depth_limit
180 The maximum amount of nesting allowed in parameters.
181 For example, if set to 3, this query string would be allowed:
185 but this query string would not be allowed:
189 Limiting the depth prevents a possible stack overflow when parsing parameters.
193 === multipart_part_limit
195 The maximum number of parts a request can contain.
196 Accepting too many part can lead to the server running out of file handles.
198 The default is 128, which means that a single request can't upload more than 128 files at once.
200 Set to 0 for no limit.
202 Can also be set via the +RACK_MULTIPART_PART_LIMIT+ environment variable.
206 No longer has an effect, deprecated.
210 See {CHANGELOG.md}[link:CHANGELOG.md].
214 See {CONTRIBUTING.md}[link:CONTRIBUTING.md].
218 Please post bugs, suggestions and patches to
219 the bug tracker at {issues}[https://github.com/rack/rack/issues].
221 Please post security related bugs and suggestions to the core team at
222 <https://groups.google.com/forum/#!forum/rack-core> or rack-core@googlegroups.com. This
223 list is not public. Due to wide usage of the library, it is strongly preferred
224 that we manage timing in order to provide viable patches at the time of
225 disclosure. Your assistance in this matter is greatly appreciated.
227 Mailing list archives are available at
228 <https://groups.google.com/forum/#!forum/rack-devel>.
230 Git repository (send Git patches to the mailing list):
232 * https://github.com/rack/rack
234 You are also welcome to join the #rack channel on irc.freenode.net.
238 The \Rack Core Team, consisting of
240 * Aaron Patterson (tenderlove[https://github.com/tenderlove])
241 * Samuel Williams (ioquatix[https://github.com/ioquatix])
242 * Jeremy Evans (jeremyevans[https://github.com/jeremyevans])
243 * Eileen Uchitelle (eileencodes[https://github.com/eileencodes])
244 * Matthew Draper (matthewd[https://github.com/matthewd])
245 * Rafael França (rafaelfranca[https://github.com/rafaelfranca])
249 * Ryan Tomayko (rtomayko[https://github.com/rtomayko])
250 * Scytrin dai Kinthra (scytrin[https://github.com/scytrin])
251 * Leah Neukirchen (leahneukirchen[https://github.com/leahneukirchen])
252 * James Tucker (raggi[https://github.com/raggi])
253 * Josh Peek (josh[https://github.com/josh])
254 * José Valim (josevalim[https://github.com/josevalim])
255 * Michael Fellinger (manveru[https://github.com/manveru])
256 * Santiago Pastorino (spastorino[https://github.com/spastorino])
257 * Konstantin Haase (rkh[https://github.com/rkh])
261 * Adrian Madrid, for the LiteSpeed handler.
262 * Christoffer Sawicki, for the first Rails adapter and Rack::Deflater.
263 * Tim Fletcher, for the HTTP authentication code.
264 * Luc Heinrich for the Cookie sessions, the static file handler and bugfixes.
265 * Armin Ronacher, for the logo and racktools.
266 * Alex Beregszaszi, Alexander Kahn, Anil Wadghule, Aredridel, Ben
267 Alpert, Dan Kubb, Daniel Roethlisberger, Matt Todd, Tom Robinson,
268 Phil Hagelberg, S. Brent Faulkner, Bosko Milekic, Daniel Rodríguez
269 Troitiño, Genki Takiuchi, Geoffrey Grosenbach, Julien Sanchez, Kamal
270 Fariz Mahyuddin, Masayoshi Takahashi, Patrick Aljordm, Mig, Kazuhiro
271 Nishiyama, Jon Bardin, Konstantin Haase, Larry Siden, Matias
272 Korhonen, Sam Ruby, Simon Chiang, Tim Connor, Timur Batyrshin, and
273 Zach Brock for bug fixing and other improvements.
274 * Eric Wong, Hongli Lai, Jeremy Kemper for their continuous support
275 and API improvements.
276 * Yehuda Katz and Carl Lerche for refactoring rackup.
277 * Brian Candler, for Rack::ContentType.
278 * Graham Batty, for improved handler loading.
279 * Stephen Bannasch, for bug reports and documentation.
280 * Gary Wright, for proposing a better Rack::Response interface.
281 * Jonathan Buch, for improvements regarding Rack::Response.
282 * Armin Röhrl, for tracking down bugs in the Cookie generator.
283 * Alexander Kellett for testing the Gem and reviewing the announcement.
284 * Marcus Rückert, for help with configuring and debugging lighttpd.
285 * The WSGI team for the well-done and documented work they've done and
287 * All bug reporters and patch contributors not mentioned above.
291 \Rack:: <https://rack.github.io/>
292 Official \Rack repositories:: <https://github.com/rack>
293 \Rack Bug Tracking:: <https://github.com/rack/rack/issues>
294 rack-devel mailing list:: <https://groups.google.com/forum/#!forum/rack-devel>
298 \Rack is released under the {MIT License}[https://opensource.org/licenses/MIT].