README.rdoc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. = Rack, a modular Ruby webserver interface {<img src="https://secure.travis-ci.org/rack/rack.png" alt="Build Status" />}[http://travis-ci.org/rack/rack] {<img src="https://gemnasium.com/rack/rack.png" alt="Dependency Status" />}[https://gemnasium.com/rack/rack]
  2. Rack provides a minimal, modular and adaptable interface for developing
  3. web applications in Ruby. By wrapping HTTP requests and responses in
  4. the simplest way possible, it unifies and distills the API for web
  5. servers, web frameworks, and software in between (the so-called
  6. middleware) into a single method call.
  7. The exact details of this are described in the Rack specification,
  8. which all Rack applications should conform to.
  9. == Supported web servers
  10. The included *handlers* connect all kinds of web servers to Rack:
  11. * Mongrel
  12. * EventedMongrel
  13. * SwiftipliedMongrel
  14. * WEBrick
  15. * FCGI
  16. * CGI
  17. * SCGI
  18. * LiteSpeed
  19. * Thin
  20. These web servers include Rack handlers in their distributions:
  21. * Ebb
  22. * Fuzed
  23. * Glassfish v3
  24. * Phusion Passenger (which is mod_rack for Apache and for nginx)
  25. * Rainbows!
  26. * Unicorn
  27. * Zbatery
  28. Any valid Rack app will run the same on all these handlers, without
  29. changing anything.
  30. == Supported web frameworks
  31. These frameworks include Rack adapters in their distributions:
  32. * Camping
  33. * Coset
  34. * Halcyon
  35. * Mack
  36. * Maveric
  37. * Merb
  38. * Racktools::SimpleApplication
  39. * Ramaze
  40. * Ruby on Rails
  41. * Rum
  42. * Sinatra
  43. * Sin
  44. * Vintage
  45. * Waves
  46. * Wee
  47. * ... and many others.
  48. Current links to these projects can be found at
  49. http://wiki.ramaze.net/Home#other-frameworks
  50. == Available middleware
  51. Between the server and the framework, Rack can be customized to your
  52. applications needs using middleware, for example:
  53. * Rack::URLMap, to route to multiple applications inside the same process.
  54. * Rack::CommonLogger, for creating Apache-style logfiles.
  55. * Rack::ShowException, for catching unhandled exceptions and
  56. presenting them in a nice and helpful way with clickable backtrace.
  57. * Rack::File, for serving static files.
  58. * ...many others!
  59. All these components use the same interface, which is described in
  60. detail in the Rack specification. These optional components can be
  61. used in any way you wish.
  62. == Convenience
  63. If you want to develop outside of existing frameworks, implement your
  64. own ones, or develop middleware, Rack provides many helpers to create
  65. Rack applications quickly and without doing the same web stuff all
  66. over:
  67. * Rack::Request, which also provides query string parsing and
  68. multipart handling.
  69. * Rack::Response, for convenient generation of HTTP replies and
  70. cookie handling.
  71. * Rack::MockRequest and Rack::MockResponse for efficient and quick
  72. testing of Rack application without real HTTP round-trips.
  73. == rack-contrib
  74. The plethora of useful middleware created the need for a project that
  75. collects fresh Rack middleware. rack-contrib includes a variety of
  76. add-on components for Rack and it is easy to contribute new modules.
  77. * http://github.com/rack/rack-contrib
  78. == rackup
  79. rackup is a useful tool for running Rack applications, which uses the
  80. Rack::Builder DSL to configure middleware and build up applications
  81. easily.
  82. rackup automatically figures out the environment it is run in, and
  83. runs your application as FastCGI, CGI, or standalone with Mongrel or
  84. WEBrick---all from the same configuration.
  85. == Quick start
  86. Try the lobster!
  87. Either with the embedded WEBrick starter:
  88. ruby -Ilib lib/rack/lobster.rb
  89. Or with rackup:
  90. bin/rackup -Ilib example/lobster.ru
  91. By default, the lobster is found at http://localhost:9292.
  92. == Installing with RubyGems
  93. A Gem of Rack is available at rubygems.org. You can install it with:
  94. gem install rack
  95. I also provide a local mirror of the gems (and development snapshots)
  96. at my site:
  97. gem install rack --source http://chneukirchen.org/releases/gems/
  98. == Running the tests
  99. Testing Rack requires the bacon testing framework:
  100. gem install bacon
  101. There are two rake-based test tasks:
  102. rake test tests all the fast tests (no Handlers or Adapters)
  103. rake fulltest runs all the tests
  104. The fast testsuite has no dependencies outside of the core Ruby
  105. installation and bacon.
  106. To run the test suite completely, you need:
  107. * fcgi
  108. * memcache-client
  109. * mongrel
  110. * thin
  111. The full set of tests test FCGI access with lighttpd (on port
  112. 9203) so you will need lighttpd installed as well as the FCGI
  113. libraries and the fcgi gem:
  114. Download and install lighttpd:
  115. http://www.lighttpd.net/download
  116. Installing the FCGI libraries:
  117. curl -O http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz
  118. tar xzvf fcgi-2.4.0.tar.gz
  119. cd fcgi-2.4.0
  120. ./configure --prefix=/usr/local
  121. make
  122. sudo make install
  123. cd ..
  124. Installing the Ruby fcgi gem:
  125. gem install fcgi
  126. Furthermore, to test Memcache sessions, you need memcached (will be
  127. run on port 11211) and memcache-client installed.
  128. == History
  129. * March 3rd, 2007: First public release 0.1.
  130. * May 16th, 2007: Second public release 0.2.
  131. * HTTP Basic authentication.
  132. * Cookie Sessions.
  133. * Static file handler.
  134. * Improved Rack::Request.
  135. * Improved Rack::Response.
  136. * Added Rack::ShowStatus, for better default error messages.
  137. * Bug fixes in the Camping adapter.
  138. * Removed Rails adapter, was too alpha.
  139. * February 26th, 2008: Third public release 0.3.
  140. * LiteSpeed handler, by Adrian Madrid.
  141. * SCGI handler, by Jeremy Evans.
  142. * Pool sessions, by blink.
  143. * OpenID authentication, by blink.
  144. * :Port and :File options for opening FastCGI sockets, by blink.
  145. * Last-Modified HTTP header for Rack::File, by blink.
  146. * Rack::Builder#use now accepts blocks, by Corey Jewett.
  147. (See example/protectedlobster.ru)
  148. * HTTP status 201 can contain a Content-Type and a body now.
  149. * Many bugfixes, especially related to Cookie handling.
  150. * August 21st, 2008: Fourth public release 0.4.
  151. * New middleware, Rack::Deflater, by Christoffer Sawicki.
  152. * OpenID authentication now needs ruby-openid 2.
  153. * New Memcache sessions, by blink.
  154. * Explicit EventedMongrel handler, by Joshua Peek <josh@joshpeek.com>
  155. * Rack::Reloader is not loaded in rackup development mode.
  156. * rackup can daemonize with -D.
  157. * Many bugfixes, especially for pool sessions, URLMap, thread safety
  158. and tempfile handling.
  159. * Improved tests.
  160. * Rack moved to Git.
  161. * January 6th, 2009: Fifth public release 0.9.
  162. * Rack is now managed by the Rack Core Team.
  163. * Rack::Lint is stricter and follows the HTTP RFCs more closely.
  164. * Added ConditionalGet middleware.
  165. * Added ContentLength middleware.
  166. * Added Deflater middleware.
  167. * Added Head middleware.
  168. * Added MethodOverride middleware.
  169. * Rack::Mime now provides popular MIME-types and their extension.
  170. * Mongrel Header now streams.
  171. * Added Thin handler.
  172. * Official support for swiftiplied Mongrel.
  173. * Secure cookies.
  174. * Made HeaderHash case-preserving.
  175. * Many bugfixes and small improvements.
  176. * January 9th, 2009: Sixth public release 0.9.1.
  177. * Fix directory traversal exploits in Rack::File and Rack::Directory.
  178. * April 25th, 2009: Seventh public release 1.0.0.
  179. * SPEC change: Rack::VERSION has been pushed to [1,0].
  180. * SPEC change: header values must be Strings now, split on "\n".
  181. * SPEC change: Content-Length can be missing, in this case chunked transfer
  182. encoding is used.
  183. * SPEC change: rack.input must be rewindable and support reading into
  184. a buffer, wrap with Rack::RewindableInput if it isn't.
  185. * SPEC change: rack.session is now specified.
  186. * SPEC change: Bodies can now additionally respond to #to_path with
  187. a filename to be served.
  188. * NOTE: String bodies break in 1.9, use an Array consisting of a
  189. single String instead.
  190. * New middleware Rack::Lock.
  191. * New middleware Rack::ContentType.
  192. * Rack::Reloader has been rewritten.
  193. * Major update to Rack::Auth::OpenID.
  194. * Support for nested parameter parsing in Rack::Response.
  195. * Support for redirects in Rack::Response.
  196. * HttpOnly cookie support in Rack::Response.
  197. * The Rakefile has been rewritten.
  198. * Many bugfixes and small improvements.
  199. * October 18th, 2009: Eighth public release 1.0.1.
  200. * Bump remainder of rack.versions.
  201. * Support the pure Ruby FCGI implementation.
  202. * Fix for form names containing "=": split first then unescape components
  203. * Fixes the handling of the filename parameter with semicolons in names.
  204. * Add anchor to nested params parsing regexp to prevent stack overflows
  205. * Use more compatible gzip write api instead of "<<".
  206. * Make sure that Reloader doesn't break when executed via ruby -e
  207. * Make sure WEBrick respects the :Host option
  208. * Many Ruby 1.9 fixes.
  209. * January 3rd, 2010: Ninth public release 1.1.0.
  210. * Moved Auth::OpenID to rack-contrib.
  211. * SPEC change that relaxes Lint slightly to allow subclasses of the
  212. required types
  213. * SPEC change to document rack.input binary mode in greator detail
  214. * SPEC define optional rack.logger specification
  215. * File servers support X-Cascade header
  216. * Imported Config middleware
  217. * Imported ETag middleware
  218. * Imported Runtime middleware
  219. * Imported Sendfile middleware
  220. * New Logger and NullLogger middlewares
  221. * Added mime type for .ogv and .manifest.
  222. * Don't squeeze PATH_INFO slashes
  223. * Use Content-Type to determine POST params parsing
  224. * Update Rack::Utils::HTTP_STATUS_CODES hash
  225. * Add status code lookup utility
  226. * Response should call #to_i on the status
  227. * Add Request#user_agent
  228. * Request#host knows about forwared host
  229. * Return an empty string for Request#host if HTTP_HOST and
  230. SERVER_NAME are both missing
  231. * Allow MockRequest to accept hash params
  232. * Optimizations to HeaderHash
  233. * Refactored rackup into Rack::Server
  234. * Added Utils.build_nested_query to complement Utils.parse_nested_query
  235. * Added Utils::Multipart.build_multipart to complement
  236. Utils::Multipart.parse_multipart
  237. * Extracted set and delete cookie helpers into Utils so they can be
  238. used outside Response
  239. * Extract parse_query and parse_multipart in Request so subclasses
  240. can change their behavior
  241. * Enforce binary encoding in RewindableInput
  242. * Set correct external_encoding for handlers that don't use RewindableInput
  243. * June 13th, 2010: Tenth public release 1.2.0.
  244. * Removed Camping adapter: Camping 2.0 supports Rack as-is
  245. * Removed parsing of quoted values
  246. * Add Request.trace? and Request.options?
  247. * Add mime-type for .webm and .htc
  248. * Fix HTTP_X_FORWARDED_FOR
  249. * Various multipart fixes
  250. * Switch test suite to bacon
  251. * June 15th, 2010: Eleventh public release 1.2.1.
  252. * Make CGI handler rewindable
  253. * Rename spec/ to test/ to not conflict with SPEC on lesser
  254. operating systems
  255. * March 13th, 2011: Twelfth public release 1.2.2/1.1.2.
  256. * Security fix in Rack::Auth::Digest::MD5: when authenticator
  257. returned nil, permission was granted on empty password.
  258. * May 22nd, 2011: Thirteenth public release 1.3.0
  259. * Various performance optimizations
  260. * Various multipart fixes
  261. * Various multipart refactors
  262. * Infinite loop fix for multipart
  263. * Test coverage for Rack::Server returns
  264. * Allow files with '..', but not path components that are '..'
  265. * rackup accepts handler-specific options on the command line
  266. * Request#params no longer merges POST into GET (but returns the same)
  267. * Use URI.encode_www_form_component instead. Use core methods for escaping.
  268. * Allow multi-line comments in the config file
  269. * Bug L#94 reported by Nikolai Lugovoi, query parameter unescaping.
  270. * Rack::Response now deletes Content-Length when appropriate
  271. * Rack::Deflater now supports streaming
  272. * Improved Rack::Handler loading and searching
  273. * Support for the PATCH verb
  274. * env['rack.session.options'] now contains session options
  275. * Cookies respect renew
  276. * Session middleware uses SecureRandom.hex
  277. * May 22nd, 2011: Fourteenth public release 1.2.3
  278. * Pulled in relevant bug fixes from 1.3
  279. * Fixed 1.8.6 support
  280. * July 13, 2011: Fifteenth public release 1.3.1
  281. * Fix 1.9.1 support
  282. * Fix JRuby support
  283. * Properly handle $KCODE in Rack::Utils.escape
  284. * Make method_missing/respond_to behavior consistent for Rack::Lock,
  285. Rack::Auth::Digest::Request and Rack::Multipart::UploadedFile
  286. * Reenable passing rack.session to session middleware
  287. * Rack::CommonLogger handles streaming responses correctly
  288. * Rack::MockResponse calls close on the body object
  289. * Fix a DOS vector from MRI stdlib backport
  290. * July 16, 2011: Sixteenth public release 1.3.2
  291. * Fix for Rails and rack-test, Rack::Utils#escape calls to_s
  292. * Not Yet Released: Seventeenth public release 1.3.3
  293. * Fix bug with broken query parameters in Rack::ShowExceptions
  294. * Rack::Request#cookies no longer swallows exceptions on broken input
  295. * Prevents XSS attacks enabled by bug in Ruby 1.8's regexp engine
  296. * Rack::ConditionalGet handles broken If-Modified-Since helpers
  297. * September 16, 2011: Eighteenth public release 1.2.4
  298. * Fix a bug with MRI regex engine to prevent XSS by malformed unicode
  299. * October 1, 2011: Nineteenth public release 1.3.4
  300. * Backport security fix from 1.9.3, also fixes some roundtrip issues in URI
  301. * Small documentation update
  302. * Fix an issue where BodyProxy could cause an infinite recursion
  303. * Add some supporting files for travis-ci
  304. * October 17, 2011: Twentieth public release 1.3.5
  305. * Fix annoying warnings caused by the backport in 1.3.4
  306. * December 28th, 2011: Twenty fourth public release 1.4.0
  307. * Ruby 1.8.6 support has officially been dropped. Not all tests pass.
  308. * Raise sane error messages for broken config.ru
  309. * Allow combining run and map in a config.ru
  310. * Rack::ContentType will not set Content-Type for responses without a body
  311. * Status code 205 does not send a response body
  312. * Rack::Response::Helpers will not rely on instance variables
  313. * Rack::Utils.build_query no longer outputs '=' for nil query values
  314. * Various mime types added
  315. * Rack::MockRequest now supports HEAD
  316. * Rack::Directory now supports files that contain RFC3986 reserved chars
  317. * Rack::File now only supports GET and HEAD requests
  318. * Rack::Server#start now passes the block to Rack::Handler::<h>#run
  319. * Rack::Static now supports an index option
  320. * Added the Teapot status code
  321. * rackup now defaults to Thin instead of Mongrel (if installed)
  322. * Support added for HTTP_X_FORWARDED_SCHEME
  323. * Numerous bug fixes, including many fixes for new and alternate rubies
  324. * January 22nd, 2012: Twenty fifth public release 1.4.1
  325. * Alter the keyspace limit calculations to reduce issues with nested params
  326. * Add a workaround for multipart parsing where files contian unescaped "%"
  327. * Added Rack::Response::Helpers#method_not_allowed? (code 405)
  328. * Rack::File now returns 404's for illegal directory traversals
  329. * Rack::File now returns 405's for illegal methods (non HEAD/GET)
  330. * Rack::Cascade now catches 405 by default, as well as 404
  331. * Cookies missing '--' no longer cause an exception to be raised
  332. * Various style changes and documentation spelling errors
  333. * Rack::BodyProxy always ensures to execute it's block
  334. * Additional test coverage around cookies and secrets
  335. * Rack::Session::Cookie can now be supplied either secret or old_secret
  336. * Tests are no longer dependent on set order
  337. * Rack::Static no longer defaults to serving index files
  338. * Rack.release was fixed
  339. == Contact
  340. Please post bugs, suggestions and patches to
  341. the bug tracker at <http://github.com/rack/rack/issues>.
  342. Mailing list archives are available at
  343. <http://groups.google.com/group/rack-devel>.
  344. Git repository (send Git patches to the mailing list):
  345. * http://github.com/rack/rack
  346. * http://git.vuxu.org/cgi-bin/gitweb.cgi?p=rack-github.git
  347. You are also welcome to join the #rack channel on irc.freenode.net.
  348. == Thanks
  349. The Rack Core Team, consisting of
  350. * Christian Neukirchen (chneukirchen)
  351. * James Tucker (raggi)
  352. * Josh Peek (josh)
  353. * Michael Fellinger (manveru)
  354. * Ryan Tomayko (rtomayko)
  355. * Scytrin dai Kinthra (scytrin)
  356. * Aaron Patterson (tenderlove)
  357. * Konstantin Haase (rkh)
  358. would like to thank:
  359. * Adrian Madrid, for the LiteSpeed handler.
  360. * Christoffer Sawicki, for the first Rails adapter and Rack::Deflater.
  361. * Tim Fletcher, for the HTTP authentication code.
  362. * Luc Heinrich for the Cookie sessions, the static file handler and bugfixes.
  363. * Armin Ronacher, for the logo and racktools.
  364. * Alex Beregszaszi, Alexander Kahn, Anil Wadghule, Aredridel, Ben
  365. Alpert, Dan Kubb, Daniel Roethlisberger, Matt Todd, Tom Robinson,
  366. Phil Hagelberg, S. Brent Faulkner, Bosko Milekic, Daniel Rodríguez
  367. Troitiño, Genki Takiuchi, Geoffrey Grosenbach, Julien Sanchez, Kamal
  368. Fariz Mahyuddin, Masayoshi Takahashi, Patrick Aljordm, Mig, Kazuhiro
  369. Nishiyama, Jon Bardin, Konstantin Haase, Larry Siden, Matias
  370. Korhonen, Sam Ruby, Simon Chiang, Tim Connor, Timur Batyrshin, and
  371. Zach Brock for bug fixing and other improvements.
  372. * Eric Wong, Hongli Lai, Jeremy Kemper for their continuous support
  373. and API improvements.
  374. * Yehuda Katz and Carl Lerche for refactoring rackup.
  375. * Brian Candler, for Rack::ContentType.
  376. * Graham Batty, for improved handler loading.
  377. * Stephen Bannasch, for bug reports and documentation.
  378. * Gary Wright, for proposing a better Rack::Response interface.
  379. * Jonathan Buch, for improvements regarding Rack::Response.
  380. * Armin Röhrl, for tracking down bugs in the Cookie generator.
  381. * Alexander Kellett for testing the Gem and reviewing the announcement.
  382. * Marcus Rückert, for help with configuring and debugging lighttpd.
  383. * The WSGI team for the well-done and documented work they've done and
  384. Rack builds up on.
  385. * All bug reporters and patch contributors not mentioned above.
  386. == Copyright
  387. Copyright (C) 2007, 2008, 2009, 2010 Christian Neukirchen <http://purl.org/net/chneukirchen>
  388. Permission is hereby granted, free of charge, to any person obtaining a copy
  389. of this software and associated documentation files (the "Software"), to
  390. deal in the Software without restriction, including without limitation the
  391. rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  392. sell copies of the Software, and to permit persons to whom the Software is
  393. furnished to do so, subject to the following conditions:
  394. The above copyright notice and this permission notice shall be included in
  395. all copies or substantial portions of the Software.
  396. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  397. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  398. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  399. THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  400. IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  401. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  402. == Links
  403. Rack:: <http://rack.rubyforge.org/>
  404. Official Rack repositories:: <http://github.com/rack>
  405. Rack Bug Tracking:: <http://github.com/rack/rack/issues>
  406. rack-devel mailing list:: <http://groups.google.com/group/rack-devel>
  407. Rack's Rubyforge project:: <http://rubyforge.org/projects/rack>
  408. Christian Neukirchen:: <http://chneukirchen.org/>