1 # ![Rack](contrib/logo.webp)
3 Rack provides a minimal, modular, and adaptable interface for developing web
4 applications in Ruby. By wrapping HTTP requests and responses in the simplest
5 way possible, it unifies and distills the bridge between web servers, web
6 frameworks, and web application into a single method call.
8 The exact details of this are described in the [Rack Specification], which all
9 Rack applications should conform to.
14 |----------|------------------------------------|
15 | 3.1.x | Bug fixes and security patches. |
16 | 3.0.x | Security patches only. |
17 | 2.2.x | Security patches only. |
18 | <= 2.1.x | End of support. |
20 Please see the [Security Policy] for more information.
24 This is the latest version of Rack. It contains bug fixes and security patches.
25 Please check the [Change Log](CHANGELOG.md) for detailed information on specific
30 This version of rack contains significant changes which are detailed in the
31 [Upgrade Guide](UPGRADE-GUIDE.md). It is recommended to upgrade to Rack 3 as soon
32 as possible to receive the latest features and security patches.
36 This version of Rack is receiving security patches only, and effort should be
37 made to move to Rack 3.
39 Starting in Ruby 3.4 the `base64` dependency will no longer be a default gem,
40 and may cause a warning or error about `base64` being missing. To correct this,
41 add `base64` as a dependency to your project.
45 Add the rack gem to your application bundle, or follow the instructions provided
46 by a [supported web framework](#supported-web-frameworks):
49 # Install it generally:
52 # or, add it to your current application gemfile:
56 If you need features from `Rack::Session` or `bin/rackup` please add those gems separately.
59 $ gem install rack-session rackup
64 Create a file called `config.ru` with the following contents:
68 [200, {}, ["Hello World"]]
72 Run this using the rackup gem or another [supported web
73 server](#supported-web-servers).
80 $ curl http://localhost:9292
84 ## Supported web servers
86 Rack is supported by a wide range of servers, including:
88 * [Agoo](https://github.com/ohler55/agoo)
89 * [Falcon](https://github.com/socketry/falcon)
90 * [Iodine](https://github.com/boazsegev/iodine)
91 * [NGINX Unit](https://unit.nginx.org/)
92 * [Phusion Passenger](https://www.phusionpassenger.com/) (which is mod_rack for
94 * [Pitchfork](https://github.com/Shopify/pitchfork)
95 * [Puma](https://puma.io/)
96 * [Thin](https://github.com/macournoyer/thin)
97 * [Unicorn](https://yhbt.net/unicorn/)
98 * [uWSGI](https://uwsgi-docs.readthedocs.io/en/latest/)
99 * [Lamby](https://lamby.custominktech.com) (for AWS Lambda)
101 You will need to consult the server documentation to find out what features and
102 limitations they may have. In general, any valid Rack app will run the same on
103 all these servers, without changing anything.
107 Rack provides a separate gem, [rackup](https://github.com/rack/rackup) which is
108 a generic interface for running a Rack application on supported servers, which
109 include `WEBRick`, `Puma`, `Falcon` and others.
111 ## Supported web frameworks
113 These frameworks and many others support the [Rack Specification]:
115 * [Camping](https://github.com/camping/camping)
116 * [Hanami](https://hanamirb.org/)
117 * [Ramaze](https://github.com/ramaze/ramaze)
118 * [Padrino](https://padrinorb.com/)
119 * [Roda](https://github.com/jeremyevans/roda)
120 * [Ruby on Rails](https://rubyonrails.org/)
121 * [Rum](https://github.com/leahneukirchen/rum)
122 * [Sinatra](https://sinatrarb.com/)
123 * [Utopia](https://github.com/socketry/utopia)
124 * [WABuR](https://github.com/ohler55/wabur)
126 ## Available middleware shipped with Rack
128 Between the server and the framework, Rack can be customized to your
129 applications needs using middleware. Rack itself ships with the following
132 * `Rack::CommonLogger` for creating Apache-style logfiles.
133 * `Rack::ConditionalGet` for returning [Not
134 Modified](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/304)
135 responses when the response has not changed.
136 * `Rack::Config` for modifying the environment before processing the request.
137 * `Rack::ContentLength` for setting a `content-length` header based on body
139 * `Rack::ContentType` for setting a default `content-type` header for responses.
140 * `Rack::Deflater` for compressing responses with gzip.
141 * `Rack::ETag` for setting `etag` header on bodies that can be buffered.
142 * `Rack::Events` for providing easy hooks when a request is received and when
143 the response is sent.
144 * `Rack::Files` for serving static files.
145 * `Rack::Head` for returning an empty body for HEAD requests.
146 * `Rack::Lint` for checking conformance to the [Rack Specification].
147 * `Rack::Lock` for serializing requests using a mutex.
148 * `Rack::MethodOverride` for modifying the request method based on a submitted
150 * `Rack::Recursive` for including data from other paths in the application, and
151 for performing internal redirects.
152 * `Rack::Reloader` for reloading files if they have been modified.
153 * `Rack::Runtime` for including a response header with the time taken to process
155 * `Rack::Sendfile` for working with web servers that can use optimized file
156 serving for file system paths.
157 * `Rack::ShowException` for catching unhandled exceptions and presenting them in
158 a nice and helpful way with clickable backtrace.
159 * `Rack::ShowStatus` for using nice error pages for empty client error
161 * `Rack::Static` for more configurable serving of static files.
162 * `Rack::TempfileReaper` for removing temporary files creating during a request.
164 All these components use the same interface, which is described in detail in the
165 [Rack Specification]. These optional components can be used in any way you wish.
167 ### Convenience interfaces
169 If you want to develop outside of existing frameworks, implement your own ones,
170 or develop middleware, Rack provides many helpers to create Rack applications
171 quickly and without doing the same web stuff all over:
173 * `Rack::Request` which also provides query string parsing and multipart
175 * `Rack::Response` for convenient generation of HTTP replies and cookie
177 * `Rack::MockRequest` and `Rack::MockResponse` for efficient and quick testing
178 of Rack application without real HTTP round-trips.
179 * `Rack::Cascade` for trying additional Rack applications if an application
180 returns a not found or method not supported response.
181 * `Rack::Directory` for serving files under a given directory, with directory
183 * `Rack::MediaType` for parsing content-type headers.
184 * `Rack::Mime` for determining content-type based on file extension.
185 * `Rack::RewindableInput` for making any IO object rewindable, using a temporary
187 * `Rack::URLMap` to route to multiple applications inside the same process.
191 Rack exposes several configuration parameters to control various features of the
194 ### `param_depth_limit`
197 Rack::Utils.param_depth_limit = 32 # default
200 The maximum amount of nesting allowed in parameters. For example, if set to 3,
201 this query string would be allowed:
207 but this query string would not be allowed:
213 Limiting the depth prevents a possible stack overflow when parsing parameters.
215 ### `multipart_file_limit`
218 Rack::Utils.multipart_file_limit = 128 # default
221 The maximum number of parts with a filename a request can contain. Accepting
222 too many parts can lead to the server running out of file handles.
224 The default is 128, which means that a single request can't upload more than 128
225 files at once. Set to 0 for no limit.
227 Can also be set via the `RACK_MULTIPART_FILE_LIMIT` environment variable.
229 (This is also aliased as `multipart_part_limit` and `RACK_MULTIPART_PART_LIMIT` for compatibility)
231 ### `multipart_total_part_limit`
233 The maximum total number of parts a request can contain of any type, including
234 both file and non-file form fields.
236 The default is 4096, which means that a single request can't contain more than
239 Set to 0 for no limit.
241 Can also be set via the `RACK_MULTIPART_TOTAL_PART_LIMIT` environment variable.
245 See [CHANGELOG.md](CHANGELOG.md).
249 See [CONTRIBUTING.md](CONTRIBUTING.md) for specific details about how to make a
250 contribution to Rack.
252 Please post bugs, suggestions and patches to [GitHub
253 Issues](https://github.com/rack/rack/issues).
255 Please check our [Security Policy](https://github.com/rack/rack/security/policy)
256 for responsible disclosure and security bug reporting process. Due to wide usage
257 of the library, it is strongly preferred that we manage timing in order to
258 provide viable patches at the time of disclosure. Your assistance in this matter
259 is greatly appreciated.
265 A useful tool for running Rack applications from the command line, including
266 `Rackup::Server` (previously `Rack::Server`) for scripting servers.
268 * https://github.com/rack/rackup
272 The plethora of useful middleware created the need for a project that collects
273 fresh Rack middleware. `rack-contrib` includes a variety of add-on components
274 for Rack and it is easy to contribute new modules.
276 * https://github.com/rack/rack-contrib
280 Provides convenient session management for Rack.
282 * https://github.com/rack/rack-session
286 The Rack Core Team, consisting of
288 * Aaron Patterson [tenderlove](https://github.com/tenderlove)
289 * Samuel Williams [ioquatix](https://github.com/ioquatix)
290 * Jeremy Evans [jeremyevans](https://github.com/jeremyevans)
291 * Eileen Uchitelle [eileencodes](https://github.com/eileencodes)
292 * Matthew Draper [matthewd](https://github.com/matthewd)
293 * Rafael França [rafaelfranca](https://github.com/rafaelfranca)
297 * Ryan Tomayko [rtomayko](https://github.com/rtomayko)
298 * Scytrin dai Kinthra [scytrin](https://github.com/scytrin)
299 * Leah Neukirchen [leahneukirchen](https://github.com/leahneukirchen)
300 * James Tucker [raggi](https://github.com/raggi)
301 * Josh Peek [josh](https://github.com/josh)
302 * José Valim [josevalim](https://github.com/josevalim)
303 * Michael Fellinger [manveru](https://github.com/manveru)
304 * Santiago Pastorino [spastorino](https://github.com/spastorino)
305 * Konstantin Haase [rkh](https://github.com/rkh)
309 * Adrian Madrid, for the LiteSpeed handler.
310 * Christoffer Sawicki, for the first Rails adapter and `Rack::Deflater`.
311 * Tim Fletcher, for the HTTP authentication code.
312 * Luc Heinrich for the Cookie sessions, the static file handler and bugfixes.
313 * Armin Ronacher, for the logo and racktools.
314 * Alex Beregszaszi, Alexander Kahn, Anil Wadghule, Aredridel, Ben Alpert, Dan
315 Kubb, Daniel Roethlisberger, Matt Todd, Tom Robinson, Phil Hagelberg, S. Brent
316 Faulkner, Bosko Milekic, Daniel Rodríguez Troitiño, Genki Takiuchi, Geoffrey
317 Grosenbach, Julien Sanchez, Kamal Fariz Mahyuddin, Masayoshi Takahashi,
318 Patrick Aljordm, Mig, Kazuhiro Nishiyama, Jon Bardin, Konstantin Haase, Larry
319 Siden, Matias Korhonen, Sam Ruby, Simon Chiang, Tim Connor, Timur Batyrshin,
320 and Zach Brock for bug fixing and other improvements.
321 * Eric Wong, Hongli Lai, Jeremy Kemper for their continuous support and API
323 * Yehuda Katz and Carl Lerche for refactoring rackup.
324 * Brian Candler, for `Rack::ContentType`.
325 * Graham Batty, for improved handler loading.
326 * Stephen Bannasch, for bug reports and documentation.
327 * Gary Wright, for proposing a better `Rack::Response` interface.
328 * Jonathan Buch, for improvements regarding `Rack::Response`.
329 * Armin Röhrl, for tracking down bugs in the Cookie generator.
330 * Alexander Kellett for testing the Gem and reviewing the announcement.
331 * Marcus Rückert, for help with configuring and debugging lighttpd.
332 * The WSGI team for the well-done and documented work they've done and Rack
334 * All bug reporters and patch contributors not mentioned above.
338 Rack is released under the [MIT License](MIT-LICENSE).
340 [Rack Specification]: SPEC.rdoc
341 [Security Policy]: SECURITY.md