rack 1.1.6 → 1.6.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. checksums.yaml +7 -0
  2. data/COPYING +1 -1
  3. data/HISTORY.md +375 -0
  4. data/KNOWN-ISSUES +23 -0
  5. data/README.rdoc +312 -0
  6. data/Rakefile +124 -0
  7. data/SPEC +125 -32
  8. data/contrib/rack.png +0 -0
  9. data/contrib/rack.svg +150 -0
  10. data/contrib/rack_logo.svg +1 -1
  11. data/contrib/rdoc.css +412 -0
  12. data/example/protectedlobster.rb +1 -1
  13. data/lib/rack/auth/abstract/handler.rb +4 -4
  14. data/lib/rack/auth/abstract/request.rb +7 -5
  15. data/lib/rack/auth/basic.rb +1 -1
  16. data/lib/rack/auth/digest/md5.rb +7 -3
  17. data/lib/rack/auth/digest/nonce.rb +1 -1
  18. data/lib/rack/auth/digest/params.rb +7 -9
  19. data/lib/rack/auth/digest/request.rb +10 -9
  20. data/lib/rack/backports/uri/common_18.rb +56 -0
  21. data/lib/rack/backports/uri/common_192.rb +52 -0
  22. data/lib/rack/backports/uri/common_193.rb +29 -0
  23. data/lib/rack/body_proxy.rb +39 -0
  24. data/lib/rack/builder.rb +106 -22
  25. data/lib/rack/cascade.rb +17 -6
  26. data/lib/rack/chunked.rb +44 -24
  27. data/lib/rack/commonlogger.rb +36 -13
  28. data/lib/rack/conditionalget.rb +49 -17
  29. data/lib/rack/config.rb +5 -0
  30. data/lib/rack/content_length.rb +14 -6
  31. data/lib/rack/content_type.rb +7 -1
  32. data/lib/rack/deflater.rb +73 -15
  33. data/lib/rack/directory.rb +18 -8
  34. data/lib/rack/etag.rb +59 -9
  35. data/lib/rack/file.rb +106 -44
  36. data/lib/rack/handler/cgi.rb +11 -11
  37. data/lib/rack/handler/fastcgi.rb +18 -6
  38. data/lib/rack/handler/lsws.rb +2 -4
  39. data/lib/rack/handler/mongrel.rb +22 -6
  40. data/lib/rack/handler/scgi.rb +16 -8
  41. data/lib/rack/handler/thin.rb +19 -4
  42. data/lib/rack/handler/webrick.rb +72 -19
  43. data/lib/rack/handler.rb +47 -14
  44. data/lib/rack/head.rb +10 -2
  45. data/lib/rack/lint.rb +260 -75
  46. data/lib/rack/lobster.rb +13 -8
  47. data/lib/rack/lock.rb +13 -3
  48. data/lib/rack/logger.rb +0 -2
  49. data/lib/rack/methodoverride.rb +27 -8
  50. data/lib/rack/mime.rb +625 -167
  51. data/lib/rack/mock.rb +78 -53
  52. data/lib/rack/multipart/generator.rb +93 -0
  53. data/lib/rack/multipart/parser.rb +253 -0
  54. data/lib/rack/multipart/uploaded_file.rb +34 -0
  55. data/lib/rack/multipart.rb +34 -0
  56. data/lib/rack/nulllogger.rb +21 -2
  57. data/lib/rack/recursive.rb +10 -5
  58. data/lib/rack/reloader.rb +3 -2
  59. data/lib/rack/request.rb +201 -74
  60. data/lib/rack/response.rb +41 -28
  61. data/lib/rack/rewindable_input.rb +15 -11
  62. data/lib/rack/runtime.rb +16 -3
  63. data/lib/rack/sendfile.rb +47 -29
  64. data/lib/rack/server.rb +223 -47
  65. data/lib/rack/session/abstract/id.rb +289 -30
  66. data/lib/rack/session/cookie.rb +133 -44
  67. data/lib/rack/session/memcache.rb +30 -56
  68. data/lib/rack/session/pool.rb +19 -43
  69. data/lib/rack/showexceptions.rb +53 -15
  70. data/lib/rack/showstatus.rb +14 -7
  71. data/lib/rack/static.rb +124 -12
  72. data/lib/rack/tempfile_reaper.rb +22 -0
  73. data/lib/rack/urlmap.rb +49 -15
  74. data/lib/rack/utils/okjson.rb +600 -0
  75. data/lib/rack/utils.rb +363 -361
  76. data/lib/rack.rb +17 -23
  77. data/rack.gemspec +11 -20
  78. data/test/builder/anything.rb +5 -0
  79. data/test/builder/comment.ru +4 -0
  80. data/test/builder/end.ru +5 -0
  81. data/test/builder/line.ru +1 -0
  82. data/test/builder/options.ru +2 -0
  83. data/test/cgi/assets/folder/test.js +1 -0
  84. data/test/cgi/assets/fonts/font.eot +1 -0
  85. data/test/cgi/assets/images/image.png +1 -0
  86. data/test/cgi/assets/index.html +1 -0
  87. data/test/cgi/assets/javascripts/app.js +1 -0
  88. data/test/cgi/assets/stylesheets/app.css +1 -0
  89. data/test/cgi/lighttpd.conf +26 -0
  90. data/test/cgi/rackup_stub.rb +6 -0
  91. data/test/cgi/sample_rackup.ru +5 -0
  92. data/test/cgi/test +9 -0
  93. data/test/cgi/test+directory/test+file +1 -0
  94. data/test/cgi/test.fcgi +8 -0
  95. data/test/cgi/test.ru +5 -0
  96. data/test/gemloader.rb +10 -0
  97. data/test/multipart/bad_robots +259 -0
  98. data/test/multipart/binary +0 -0
  99. data/test/multipart/content_type_and_no_filename +6 -0
  100. data/test/multipart/empty +10 -0
  101. data/test/multipart/fail_16384_nofile +814 -0
  102. data/test/multipart/file1.txt +1 -0
  103. data/test/multipart/filename_and_modification_param +7 -0
  104. data/test/multipart/filename_and_no_name +6 -0
  105. data/test/multipart/filename_with_escaped_quotes +6 -0
  106. data/test/multipart/filename_with_escaped_quotes_and_modification_param +7 -0
  107. data/test/multipart/filename_with_null_byte +7 -0
  108. data/test/multipart/filename_with_percent_escaped_quotes +6 -0
  109. data/test/multipart/filename_with_unescaped_percentages +6 -0
  110. data/test/multipart/filename_with_unescaped_percentages2 +6 -0
  111. data/test/multipart/filename_with_unescaped_percentages3 +6 -0
  112. data/test/multipart/filename_with_unescaped_quotes +6 -0
  113. data/test/multipart/ie +6 -0
  114. data/test/multipart/invalid_character +6 -0
  115. data/test/multipart/mixed_files +21 -0
  116. data/test/multipart/nested +10 -0
  117. data/test/multipart/none +9 -0
  118. data/test/multipart/semicolon +6 -0
  119. data/test/multipart/text +15 -0
  120. data/test/multipart/three_files_three_fields +31 -0
  121. data/test/multipart/webkit +32 -0
  122. data/test/rackup/config.ru +31 -0
  123. data/test/registering_handler/rack/handler/registering_myself.rb +8 -0
  124. data/test/{spec_rack_auth_basic.rb → spec_auth_basic.rb} +23 -15
  125. data/test/{spec_rack_auth_digest.rb → spec_auth_digest.rb} +56 -29
  126. data/test/spec_body_proxy.rb +85 -0
  127. data/test/spec_builder.rb +223 -0
  128. data/test/{spec_rack_cascade.rb → spec_cascade.rb} +28 -15
  129. data/test/{spec_rack_cgi.rb → spec_cgi.rb} +44 -31
  130. data/test/spec_chunked.rb +101 -0
  131. data/test/spec_commonlogger.rb +93 -0
  132. data/test/spec_conditionalget.rb +102 -0
  133. data/test/{spec_rack_config.rb → spec_config.rb} +6 -8
  134. data/test/spec_content_length.rb +85 -0
  135. data/test/spec_content_type.rb +45 -0
  136. data/test/spec_deflater.rb +339 -0
  137. data/test/{spec_rack_directory.rb → spec_directory.rb} +37 -10
  138. data/test/spec_etag.rb +107 -0
  139. data/test/{spec_rack_fastcgi.rb → spec_fastcgi.rb} +47 -29
  140. data/test/spec_file.rb +221 -0
  141. data/test/spec_handler.rb +72 -0
  142. data/test/spec_head.rb +45 -0
  143. data/test/{spec_rack_lint.rb → spec_lint.rb} +82 -60
  144. data/test/spec_lobster.rb +58 -0
  145. data/test/spec_lock.rb +164 -0
  146. data/test/spec_logger.rb +23 -0
  147. data/test/spec_methodoverride.rb +95 -0
  148. data/test/spec_mime.rb +51 -0
  149. data/test/{spec_rack_mock.rb → spec_mock.rb} +92 -38
  150. data/test/{spec_rack_mongrel.rb → spec_mongrel.rb} +46 -53
  151. data/test/spec_multipart.rb +600 -0
  152. data/test/spec_nulllogger.rb +20 -0
  153. data/test/spec_recursive.rb +72 -0
  154. data/test/spec_request.rb +1227 -0
  155. data/test/spec_response.rb +407 -0
  156. data/test/spec_rewindable_input.rb +118 -0
  157. data/test/spec_runtime.rb +49 -0
  158. data/test/spec_sendfile.rb +130 -0
  159. data/test/spec_server.rb +167 -0
  160. data/test/spec_session_abstract_id.rb +53 -0
  161. data/test/spec_session_cookie.rb +410 -0
  162. data/test/{spec_rack_session_memcache.rb → spec_session_memcache.rb} +119 -71
  163. data/test/{spec_rack_session_pool.rb → spec_session_pool.rb} +106 -69
  164. data/test/spec_showexceptions.rb +85 -0
  165. data/test/spec_showstatus.rb +103 -0
  166. data/test/spec_static.rb +145 -0
  167. data/test/spec_tempfile_reaper.rb +63 -0
  168. data/test/{spec_rack_thin.rb → spec_thin.rb} +35 -35
  169. data/test/{spec_rack_urlmap.rb → spec_urlmap.rb} +40 -19
  170. data/test/spec_utils.rb +647 -0
  171. data/test/spec_version.rb +17 -0
  172. data/test/spec_webrick.rb +184 -0
  173. data/test/static/another/index.html +1 -0
  174. data/test/static/index.html +1 -0
  175. data/test/testrequest.rb +78 -0
  176. data/test/unregistered_handler/rack/handler/unregistered.rb +7 -0
  177. data/test/unregistered_handler/rack/handler/unregistered_long_one.rb +7 -0
  178. metadata +220 -239
  179. data/RDOX +0 -0
  180. data/README +0 -592
  181. data/lib/rack/adapter/camping.rb +0 -22
  182. data/test/spec_auth.rb +0 -57
  183. data/test/spec_rack_builder.rb +0 -84
  184. data/test/spec_rack_camping.rb +0 -55
  185. data/test/spec_rack_chunked.rb +0 -62
  186. data/test/spec_rack_commonlogger.rb +0 -61
  187. data/test/spec_rack_conditionalget.rb +0 -41
  188. data/test/spec_rack_content_length.rb +0 -43
  189. data/test/spec_rack_content_type.rb +0 -30
  190. data/test/spec_rack_deflater.rb +0 -127
  191. data/test/spec_rack_etag.rb +0 -17
  192. data/test/spec_rack_file.rb +0 -75
  193. data/test/spec_rack_handler.rb +0 -43
  194. data/test/spec_rack_head.rb +0 -30
  195. data/test/spec_rack_lobster.rb +0 -45
  196. data/test/spec_rack_lock.rb +0 -38
  197. data/test/spec_rack_logger.rb +0 -21
  198. data/test/spec_rack_methodoverride.rb +0 -60
  199. data/test/spec_rack_nulllogger.rb +0 -13
  200. data/test/spec_rack_recursive.rb +0 -77
  201. data/test/spec_rack_request.rb +0 -594
  202. data/test/spec_rack_response.rb +0 -221
  203. data/test/spec_rack_rewindable_input.rb +0 -118
  204. data/test/spec_rack_runtime.rb +0 -35
  205. data/test/spec_rack_sendfile.rb +0 -86
  206. data/test/spec_rack_session_cookie.rb +0 -92
  207. data/test/spec_rack_showexceptions.rb +0 -21
  208. data/test/spec_rack_showstatus.rb +0 -72
  209. data/test/spec_rack_static.rb +0 -37
  210. data/test/spec_rack_utils.rb +0 -557
  211. data/test/spec_rack_webrick.rb +0 -130
  212. data/test/spec_rackup.rb +0 -164
data/README.rdoc ADDED
@@ -0,0 +1,312 @@
1
+ = Rack, a modular Ruby webserver interface {<img src="https://secure.travis-ci.org/rack/rack.svg" alt="Build Status" />}[http://travis-ci.org/rack/rack] {<img src="https://gemnasium.com/rack/rack.svg" alt="Dependency Status" />}[https://gemnasium.com/rack/rack]
2
+
3
+ Rack provides a minimal, modular and adaptable interface for developing
4
+ web applications in Ruby. By wrapping HTTP requests and responses in
5
+ the simplest way possible, it unifies and distills the API for web
6
+ servers, web frameworks, and software in between (the so-called
7
+ middleware) into a single method call.
8
+
9
+ The exact details of this are described in the Rack specification,
10
+ which all Rack applications should conform to.
11
+
12
+ == Supported web servers
13
+
14
+ The included *handlers* connect all kinds of web servers to Rack:
15
+ * Mongrel
16
+ * EventedMongrel
17
+ * SwiftipliedMongrel
18
+ * WEBrick
19
+ * FCGI
20
+ * CGI
21
+ * SCGI
22
+ * LiteSpeed
23
+ * Thin
24
+
25
+ These web servers include Rack handlers in their distributions:
26
+ * Ebb
27
+ * Fuzed
28
+ * Glassfish v3
29
+ * Phusion Passenger (which is mod_rack for Apache and for nginx)
30
+ * Puma
31
+ * Rainbows!
32
+ * Reel
33
+ * Unicorn
34
+ * unixrack
35
+ * uWSGI
36
+ * yahns
37
+ * Zbatery
38
+
39
+ Any valid Rack app will run the same on all these handlers, without
40
+ changing anything.
41
+
42
+ == Supported web frameworks
43
+
44
+ These frameworks include Rack adapters in their distributions:
45
+ * Camping
46
+ * Coset
47
+ * Espresso
48
+ * Halcyon
49
+ * Mack
50
+ * Maveric
51
+ * Merb
52
+ * Racktools::SimpleApplication
53
+ * Ramaze
54
+ * Ruby on Rails
55
+ * Rum
56
+ * Sinatra
57
+ * Sin
58
+ * Vintage
59
+ * Waves
60
+ * Wee
61
+ * ... and many others.
62
+
63
+ == Available middleware
64
+
65
+ Between the server and the framework, Rack can be customized to your
66
+ applications needs using middleware, for example:
67
+ * Rack::URLMap, to route to multiple applications inside the same process.
68
+ * Rack::CommonLogger, for creating Apache-style logfiles.
69
+ * Rack::ShowException, for catching unhandled exceptions and
70
+ presenting them in a nice and helpful way with clickable backtrace.
71
+ * Rack::File, for serving static files.
72
+ * ...many others!
73
+
74
+ All these components use the same interface, which is described in
75
+ detail in the Rack specification. These optional components can be
76
+ used in any way you wish.
77
+
78
+ == Convenience
79
+
80
+ If you want to develop outside of existing frameworks, implement your
81
+ own ones, or develop middleware, Rack provides many helpers to create
82
+ Rack applications quickly and without doing the same web stuff all
83
+ over:
84
+ * Rack::Request, which also provides query string parsing and
85
+ multipart handling.
86
+ * Rack::Response, for convenient generation of HTTP replies and
87
+ cookie handling.
88
+ * Rack::MockRequest and Rack::MockResponse for efficient and quick
89
+ testing of Rack application without real HTTP round-trips.
90
+
91
+ == rack-contrib
92
+
93
+ The plethora of useful middleware created the need for a project that
94
+ collects fresh Rack middleware. rack-contrib includes a variety of
95
+ add-on components for Rack and it is easy to contribute new modules.
96
+
97
+ * https://github.com/rack/rack-contrib
98
+
99
+ == rackup
100
+
101
+ rackup is a useful tool for running Rack applications, which uses the
102
+ Rack::Builder DSL to configure middleware and build up applications
103
+ easily.
104
+
105
+ rackup automatically figures out the environment it is run in, and
106
+ runs your application as FastCGI, CGI, or standalone with Mongrel or
107
+ WEBrick---all from the same configuration.
108
+
109
+ == Quick start
110
+
111
+ Try the lobster!
112
+
113
+ Either with the embedded WEBrick starter:
114
+
115
+ ruby -Ilib lib/rack/lobster.rb
116
+
117
+ Or with rackup:
118
+
119
+ bin/rackup -Ilib example/lobster.ru
120
+
121
+ By default, the lobster is found at http://localhost:9292.
122
+
123
+ == Installing with RubyGems
124
+
125
+ A Gem of Rack is available at rubygems.org. You can install it with:
126
+
127
+ gem install rack
128
+
129
+ I also provide a local mirror of the gems (and development snapshots)
130
+ at my site:
131
+
132
+ gem install rack --source http://chneukirchen.org/releases/gems/
133
+
134
+ == Running the tests
135
+
136
+ Testing Rack requires the bacon testing framework:
137
+
138
+ bundle install --without extra # to be able to run the fast tests
139
+
140
+ Or:
141
+
142
+ bundle install # this assumes that you have installed native extensions!
143
+
144
+ There are two rake-based test tasks:
145
+
146
+ rake test tests all the fast tests (no Handlers or Adapters)
147
+ rake fulltest runs all the tests
148
+
149
+ The fast testsuite has no dependencies outside of the core Ruby
150
+ installation and bacon.
151
+
152
+ To run the test suite completely, you need:
153
+
154
+ * fcgi
155
+ * memcache-client
156
+ * mongrel
157
+ * thin
158
+
159
+ The full set of tests test FCGI access with lighttpd (on port
160
+ 9203) so you will need lighttpd installed as well as the FCGI
161
+ libraries and the fcgi gem:
162
+
163
+ Download and install lighttpd:
164
+
165
+ http://www.lighttpd.net/download
166
+
167
+ Installing the FCGI libraries:
168
+
169
+ curl -O http://www.fastcgi.com/dist/fcgi-2.4.0.tar.gz
170
+ tar xzvf fcgi-2.4.0.tar.gz
171
+ cd fcgi-2.4.0
172
+ ./configure --prefix=/usr/local
173
+ make
174
+ sudo make install
175
+ cd ..
176
+
177
+ Installing the Ruby fcgi gem:
178
+
179
+ gem install fcgi
180
+
181
+ Furthermore, to test Memcache sessions, you need memcached (will be
182
+ run on port 11211) and memcache-client installed.
183
+
184
+ == Configuration
185
+
186
+ Several parameters can be modified on Rack::Utils to configure Rack behaviour.
187
+
188
+ e.g:
189
+
190
+ Rack::Utils.key_space_limit = 128
191
+
192
+ === key_space_limit
193
+
194
+ The default number of bytes to allow a single parameter key to take up.
195
+ This helps prevent a rogue client from flooding a Request.
196
+
197
+ Default to 65536 characters (4 kiB in worst case).
198
+
199
+ === multipart_part_limit
200
+
201
+ The maximum number of parts a request can contain.
202
+ Accepting too many part can lead to the server running out of file handles.
203
+
204
+ The default is 128, which means that a single request can't upload more than 128 files at once.
205
+
206
+ Set to 0 for no limit.
207
+
208
+ Can also be set via the RACK_MULTIPART_PART_LIMIT environment variable.
209
+
210
+ == History
211
+
212
+ See <https://github.com/rack/HISTORY.md>.
213
+
214
+ == Contact
215
+
216
+ Please post bugs, suggestions and patches to
217
+ the bug tracker at <https://github.com/rack/rack/issues>.
218
+
219
+ Please post security related bugs and suggestions to the core team at
220
+ <https://groups.google.com/group/rack-core> or rack-core@googlegroups.com. This
221
+ list is not public. Due to wide usage of the library, it is strongly preferred
222
+ that we manage timing in order to provide viable patches at the time of
223
+ disclosure. Your assistance in this matter is greatly appreciated.
224
+
225
+ Mailing list archives are available at
226
+ <https://groups.google.com/group/rack-devel>.
227
+
228
+ Git repository (send Git patches to the mailing list):
229
+ * https://github.com/rack/rack
230
+ * http://git.vuxu.org/cgi-bin/gitweb.cgi?p=rack-github.git
231
+
232
+ You are also welcome to join the #rack channel on irc.freenode.net.
233
+
234
+ == Thanks
235
+
236
+ The Rack Core Team, consisting of
237
+
238
+ * Christian Neukirchen (chneukirchen)
239
+ * James Tucker (raggi)
240
+ * Josh Peek (josh)
241
+ * José Valim (josevalim)
242
+ * Michael Fellinger (manveru)
243
+ * Aaron Patterson (tenderlove)
244
+ * Santiago Pastorino (spastorino)
245
+ * Konstantin Haase (rkh)
246
+
247
+ and the Rack Alumnis
248
+
249
+ * Ryan Tomayko (rtomayko)
250
+ * Scytrin dai Kinthra (scytrin)
251
+
252
+ would like to thank:
253
+
254
+ * Adrian Madrid, for the LiteSpeed handler.
255
+ * Christoffer Sawicki, for the first Rails adapter and Rack::Deflater.
256
+ * Tim Fletcher, for the HTTP authentication code.
257
+ * Luc Heinrich for the Cookie sessions, the static file handler and bugfixes.
258
+ * Armin Ronacher, for the logo and racktools.
259
+ * Alex Beregszaszi, Alexander Kahn, Anil Wadghule, Aredridel, Ben
260
+ Alpert, Dan Kubb, Daniel Roethlisberger, Matt Todd, Tom Robinson,
261
+ Phil Hagelberg, S. Brent Faulkner, Bosko Milekic, Daniel Rodríguez
262
+ Troitiño, Genki Takiuchi, Geoffrey Grosenbach, Julien Sanchez, Kamal
263
+ Fariz Mahyuddin, Masayoshi Takahashi, Patrick Aljordm, Mig, Kazuhiro
264
+ Nishiyama, Jon Bardin, Konstantin Haase, Larry Siden, Matias
265
+ Korhonen, Sam Ruby, Simon Chiang, Tim Connor, Timur Batyrshin, and
266
+ Zach Brock for bug fixing and other improvements.
267
+ * Eric Wong, Hongli Lai, Jeremy Kemper for their continuous support
268
+ and API improvements.
269
+ * Yehuda Katz and Carl Lerche for refactoring rackup.
270
+ * Brian Candler, for Rack::ContentType.
271
+ * Graham Batty, for improved handler loading.
272
+ * Stephen Bannasch, for bug reports and documentation.
273
+ * Gary Wright, for proposing a better Rack::Response interface.
274
+ * Jonathan Buch, for improvements regarding Rack::Response.
275
+ * Armin Röhrl, for tracking down bugs in the Cookie generator.
276
+ * Alexander Kellett for testing the Gem and reviewing the announcement.
277
+ * Marcus Rückert, for help with configuring and debugging lighttpd.
278
+ * The WSGI team for the well-done and documented work they've done and
279
+ Rack builds up on.
280
+ * All bug reporters and patch contributors not mentioned above.
281
+
282
+ == Copyright
283
+
284
+ Copyright (C) 2007, 2008, 2009, 2010 Christian Neukirchen <http://purl.org/net/chneukirchen>
285
+
286
+ Permission is hereby granted, free of charge, to any person obtaining a copy
287
+ of this software and associated documentation files (the "Software"), to
288
+ deal in the Software without restriction, including without limitation the
289
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
290
+ sell copies of the Software, and to permit persons to whom the Software is
291
+ furnished to do so, subject to the following conditions:
292
+
293
+ The above copyright notice and this permission notice shall be included in
294
+ all copies or substantial portions of the Software.
295
+
296
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
297
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
298
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
299
+ THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
300
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
301
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
302
+
303
+ == Links
304
+
305
+ Rack:: <http://rack.github.io/>
306
+ Official Rack repositories:: <https://github.com/rack>
307
+ Rack Bug Tracking:: <https://github.com/rack/rack/issues>
308
+ rack-devel mailing list:: <https://groups.google.com/group/rack-devel>
309
+ Rack's Rubyforge project:: <http://rubyforge.org/projects/rack>
310
+
311
+ Christian Neukirchen:: <http://chneukirchen.org/>
312
+
data/Rakefile ADDED
@@ -0,0 +1,124 @@
1
+ # Rakefile for Rack. -*-ruby-*-
2
+
3
+ desc "Run all the tests"
4
+ task :default => [:test]
5
+
6
+ desc "Install gem dependencies"
7
+ task :deps do
8
+ require 'rubygems'
9
+ spec = Gem::Specification.load('rack.gemspec')
10
+ spec.dependencies.each do |dep|
11
+ reqs = dep.requirements_list
12
+ reqs = (["-v"] * reqs.size).zip(reqs).flatten
13
+ # Use system over sh, because we want to ignore errors!
14
+ system Gem.ruby, "-S", "gem", "install", '--conservative', dep.name, *reqs
15
+ end
16
+ end
17
+
18
+ desc "Make an archive as .tar.gz"
19
+ task :dist => %w[chmod ChangeLog SPEC rdoc] do
20
+ sh "git archive --format=tar --prefix=#{release}/ HEAD^{tree} >#{release}.tar"
21
+ sh "pax -waf #{release}.tar -s ':^:#{release}/:' SPEC ChangeLog doc rack.gemspec"
22
+ sh "gzip -f -9 #{release}.tar"
23
+ end
24
+
25
+ desc "Make an official release"
26
+ task :officialrelease do
27
+ puts "Official build for #{release}..."
28
+ sh "rm -rf stage"
29
+ sh "git clone --shared . stage"
30
+ sh "cd stage && rake officialrelease_really"
31
+ sh "mv stage/#{release}.tar.gz stage/#{release}.gem ."
32
+ end
33
+
34
+ task :officialrelease_really => %w[SPEC dist gem] do
35
+ sh "shasum #{release}.tar.gz #{release}.gem"
36
+ end
37
+
38
+ def release
39
+ "rack-#{File.read("rack.gemspec")[/s.version *= *"(.*?)"/, 1]}"
40
+ end
41
+
42
+ desc "Make binaries executable"
43
+ task :chmod do
44
+ Dir["bin/*"].each { |binary| File.chmod(0755, binary) }
45
+ Dir["test/cgi/test*"].each { |binary| File.chmod(0755, binary) }
46
+ end
47
+
48
+ desc "Generate a ChangeLog"
49
+ task :changelog => %w[ChangeLog]
50
+
51
+ file '.git/index'
52
+ file "ChangeLog" => '.git/index' do
53
+ File.open("ChangeLog", "w") { |out|
54
+ log = `git log -z`
55
+ log.force_encoding(Encoding::BINARY) if log.respond_to?(:force_encoding)
56
+ log.split("\0").map { |chunk|
57
+ author = chunk[/Author: (.*)/, 1].strip
58
+ date = chunk[/Date: (.*)/, 1].strip
59
+ desc, detail = $'.strip.split("\n", 2)
60
+ detail ||= ""
61
+ detail = detail.gsub(/.*darcs-hash:.*/, '')
62
+ detail.rstrip!
63
+ out.puts "#{date} #{author}"
64
+ out.puts " * #{desc.strip}"
65
+ out.puts detail unless detail.empty?
66
+ out.puts
67
+ }
68
+ }
69
+ end
70
+
71
+ file 'lib/rack/lint.rb'
72
+ desc "Generate Rack Specification"
73
+ file "SPEC" => 'lib/rack/lint.rb' do
74
+ File.open("SPEC", "wb") { |file|
75
+ IO.foreach("lib/rack/lint.rb") { |line|
76
+ if line =~ /## (.*)/
77
+ file.puts $1
78
+ end
79
+ }
80
+ }
81
+ end
82
+
83
+ desc "Run all the fast + platform agnostic tests"
84
+ task :test => 'SPEC' do
85
+ opts = ENV['TEST'] || '-a'
86
+ specopts = ENV['TESTOPTS'] ||
87
+ "-q -t '^(?!Rack::Adapter|Rack::Session::Memcache|Rack::Server|Rack::Handler)'"
88
+
89
+ sh "bacon -w -I./lib:./test #{opts} #{specopts}"
90
+ end
91
+
92
+ desc "Run all the tests we run on CI"
93
+ task :ci => :fulltest
94
+
95
+ desc "Run all the tests"
96
+ task :fulltest => %w[SPEC chmod] do
97
+ opts = ENV['TEST'] || '-a'
98
+ specopts = ENV['TESTOPTS'] || '-q'
99
+ sh "bacon -r./test/gemloader -I./lib:./test -w #{opts} #{specopts}"
100
+ end
101
+
102
+ task :gem => ["SPEC"] do
103
+ sh "gem build rack.gemspec"
104
+ end
105
+
106
+ task :doc => :rdoc
107
+ desc "Generate RDoc documentation"
108
+ task :rdoc => %w[ChangeLog SPEC] do
109
+ sh(*%w{rdoc --line-numbers --main README.rdoc
110
+ --title 'Rack\ Documentation' --charset utf-8 -U -o doc} +
111
+ %w{README.rdoc KNOWN-ISSUES SPEC ChangeLog} +
112
+ `git ls-files lib/\*\*/\*.rb`.strip.split)
113
+ cp "contrib/rdoc.css", "doc/rdoc.css"
114
+ end
115
+
116
+ task :pushdoc => %w[rdoc] do
117
+ sh "rsync -avz doc/ rack.rubyforge.org:/var/www/gforge-projects/rack/doc/"
118
+ end
119
+
120
+ task :pushsite => %w[pushdoc] do
121
+ sh "cd site && git gc"
122
+ sh "rsync -avz site/ rack.rubyforge.org:/var/www/gforge-projects/rack/"
123
+ sh "cd site && git push"
124
+ end
data/SPEC CHANGED
@@ -3,7 +3,7 @@ can (and should) use Rack::Lint to enforce it.
3
3
  When you develop middleware, be sure to add a Lint before and
4
4
  after to catch all mistakes.
5
5
  = Rack applications
6
- A Rack application is an Ruby object (not a class) that
6
+ A Rack application is a Ruby object (not a class) that
7
7
  responds to +call+.
8
8
  It takes exactly one argument, the *environment*
9
9
  and returns an Array of exactly three values:
@@ -11,9 +11,9 @@ The *status*,
11
11
  the *headers*,
12
12
  and the *body*.
13
13
  == The Environment
14
- The environment must be an true instance of Hash (no
15
- subclassing allowed) that includes CGI-like headers.
16
- The application is free to modify the environment.
14
+ The environment must be an instance of Hash that includes
15
+ CGI-like headers. The application is free to modify the
16
+ environment.
17
17
  The environment is required to include these variables
18
18
  (adopted from PEP333), except when they'd be empty, but see
19
19
  below.
@@ -40,7 +40,17 @@ below.
40
40
  <tt>QUERY_STRING</tt>:: The portion of the request URL that
41
41
  follows the <tt>?</tt>, if any. May be
42
42
  empty, but is always required!
43
- <tt>SERVER_NAME</tt>, <tt>SERVER_PORT</tt>:: When combined with <tt>SCRIPT_NAME</tt> and <tt>PATH_INFO</tt>, these variables can be used to complete the URL. Note, however, that <tt>HTTP_HOST</tt>, if present, should be used in preference to <tt>SERVER_NAME</tt> for reconstructing the request URL. <tt>SERVER_NAME</tt> and <tt>SERVER_PORT</tt> can never be empty strings, and so are always required.
43
+ <tt>SERVER_NAME</tt>, <tt>SERVER_PORT</tt>::
44
+ When combined with <tt>SCRIPT_NAME</tt> and
45
+ <tt>PATH_INFO</tt>, these variables can be
46
+ used to complete the URL. Note, however,
47
+ that <tt>HTTP_HOST</tt>, if present,
48
+ should be used in preference to
49
+ <tt>SERVER_NAME</tt> for reconstructing
50
+ the request URL.
51
+ <tt>SERVER_NAME</tt> and <tt>SERVER_PORT</tt>
52
+ can never be empty strings, and so
53
+ are always required.
44
54
  <tt>HTTP_</tt> Variables:: Variables corresponding to the
45
55
  client-supplied HTTP request
46
56
  headers (i.e., variables whose
@@ -49,20 +59,47 @@ below.
49
59
  variables should correspond with
50
60
  the presence or absence of the
51
61
  appropriate HTTP header in the
52
- request.
62
+ request. See
63
+ <a href="https://tools.ietf.org/html/rfc3875#section-4.1.18">
64
+ RFC3875 section 4.1.18</a> for
65
+ specific behavior.
53
66
  In addition to this, the Rack environment must include these
54
67
  Rack-specific variables:
55
- <tt>rack.version</tt>:: The Array [1,1], representing this version of Rack.
56
- <tt>rack.url_scheme</tt>:: +http+ or +https+, depending on the request URL.
68
+ <tt>rack.version</tt>:: The Array representing this version of Rack
69
+ See Rack::VERSION, that corresponds to
70
+ the version of this SPEC.
71
+ <tt>rack.url_scheme</tt>:: +http+ or +https+, depending on the
72
+ request URL.
57
73
  <tt>rack.input</tt>:: See below, the input stream.
58
74
  <tt>rack.errors</tt>:: See below, the error stream.
59
- <tt>rack.multithread</tt>:: true if the application object may be simultaneously invoked by another thread in the same process, false otherwise.
60
- <tt>rack.multiprocess</tt>:: true if an equivalent application object may be simultaneously invoked by another process, false otherwise.
61
- <tt>rack.run_once</tt>:: true if the server expects (but does not guarantee!) that the application will only be invoked this one time during the life of its containing process. Normally, this will only be true for a server based on CGI (or something similar).
75
+ <tt>rack.multithread</tt>:: true if the application object may be
76
+ simultaneously invoked by another thread
77
+ in the same process, false otherwise.
78
+ <tt>rack.multiprocess</tt>:: true if an equivalent application object
79
+ may be simultaneously invoked by another
80
+ process, false otherwise.
81
+ <tt>rack.run_once</tt>:: true if the server expects
82
+ (but does not guarantee!) that the
83
+ application will only be invoked this one
84
+ time during the life of its containing
85
+ process. Normally, this will only be true
86
+ for a server based on CGI
87
+ (or something similar).
88
+ <tt>rack.hijack?</tt>:: present and true if the server supports
89
+ connection hijacking. See below, hijacking.
90
+ <tt>rack.hijack</tt>:: an object responding to #call that must be
91
+ called at least once before using
92
+ rack.hijack_io.
93
+ It is recommended #call return rack.hijack_io
94
+ as well as setting it in env if necessary.
95
+ <tt>rack.hijack_io</tt>:: if rack.hijack? is true, and rack.hijack
96
+ has received #call, this will contain
97
+ an object resembling an IO. See hijacking.
62
98
  Additional environment specifications have approved to
63
99
  standardized middleware APIs. None of these are required to
64
100
  be implemented by the server.
65
- <tt>rack.session</tt>:: A hash like interface for storing request session data.
101
+ <tt>rack.session</tt>:: A hash like interface for storing
102
+ request session data.
66
103
  The store must implement:
67
104
  store(key, value) (aliased as []=);
68
105
  fetch(key, default = nil) (aliased as []);
@@ -75,6 +112,8 @@ be implemented by the server.
75
112
  warn(message, &block)
76
113
  error(message, &block)
77
114
  fatal(message, &block)
115
+ <tt>rack.multipart.buffer_size</tt>:: An Integer hint to the multipart parser as to what chunk size to use for reads and writes.
116
+ <tt>rack.multipart.tempfile_factory</tt>:: An object responding to #call with two arguments, the filename and content_type given for the multipart form field, and returning an IO-like object that responds to #<< and optionally #rewind. This factory will be used to instantiate the tempfile for each multipart form file upload field, rather than the default class of Tempfile.
78
117
  The server or the application can store their own data in the
79
118
  environment, too. The keys must contain at least one dot,
80
119
  and should be prefixed uniquely. The prefix <tt>rack.</tt>
@@ -89,6 +128,7 @@ There are the following restrictions:
89
128
  * <tt>rack.url_scheme</tt> must either be +http+ or +https+.
90
129
  * There must be a valid input stream in <tt>rack.input</tt>.
91
130
  * There must be a valid error stream in <tt>rack.errors</tt>.
131
+ * There may be a valid hijack stream in <tt>rack.hijack_io</tt>
92
132
  * The <tt>REQUEST_METHOD</tt> must be a valid token.
93
133
  * The <tt>SCRIPT_NAME</tt>, if non-empty, must start with <tt>/</tt>
94
134
  * The <tt>PATH_INFO</tt>, if non-empty, must start with <tt>/</tt>
@@ -105,15 +145,18 @@ must be opened in binary mode, for Ruby 1.9 compatibility.
105
145
  The input stream must respond to +gets+, +each+, +read+ and +rewind+.
106
146
  * +gets+ must be called without arguments and return a string,
107
147
  or +nil+ on EOF.
108
- * +read+ behaves like IO#read. Its signature is <tt>read([length, [buffer]])</tt>.
109
- If given, +length+ must be an non-negative Integer (>= 0) or +nil+, and +buffer+ must
110
- be a String and may not be nil. If +length+ is given and not nil, then this method
111
- reads at most +length+ bytes from the input stream. If +length+ is not given or nil,
112
- then this method reads all data until EOF.
113
- When EOF is reached, this method returns nil if +length+ is given and not nil, or ""
114
- if +length+ is not given or is nil.
115
- If +buffer+ is given, then the read data will be placed into +buffer+ instead of a
116
- newly created String object.
148
+ * +read+ behaves like IO#read.
149
+ Its signature is <tt>read([length, [buffer]])</tt>.
150
+ If given, +length+ must be a non-negative Integer (>= 0) or +nil+,
151
+ and +buffer+ must be a String and may not be nil.
152
+ If +length+ is given and not nil, then this method reads at most
153
+ +length+ bytes from the input stream.
154
+ If +length+ is not given or nil, then this method reads
155
+ all data until EOF.
156
+ When EOF is reached, this method returns nil if +length+ is given
157
+ and not nil, or "" if +length+ is not given or is nil.
158
+ If +buffer+ is given, then the read data will be placed
159
+ into +buffer+ instead of a newly created String object.
117
160
  * +each+ must be called without arguments and only yield Strings.
118
161
  * +rewind+ must be called without arguments. It rewinds the input
119
162
  stream back to the beginning. It must not raise Errno::ESPIPE:
@@ -128,35 +171,85 @@ The error stream must respond to +puts+, +write+ and +flush+.
128
171
  * +flush+ must be called without arguments and must be called
129
172
  in order to make the error appear for sure.
130
173
  * +close+ must never be called on the error stream.
174
+ === Hijacking
175
+ ==== Request (before status)
176
+ If rack.hijack? is true then rack.hijack must respond to #call.
177
+ rack.hijack must return the io that will also be assigned (or is
178
+ already present, in rack.hijack_io.
179
+ rack.hijack_io must respond to:
180
+ <tt>read, write, read_nonblock, write_nonblock, flush, close,
181
+ close_read, close_write, closed?</tt>
182
+ The semantics of these IO methods must be a best effort match to
183
+ those of a normal ruby IO or Socket object, using standard
184
+ arguments and raising standard exceptions. Servers are encouraged
185
+ to simply pass on real IO objects, although it is recognized that
186
+ this approach is not directly compatible with SPDY and HTTP 2.0.
187
+ IO provided in rack.hijack_io should preference the
188
+ IO::WaitReadable and IO::WaitWritable APIs wherever supported.
189
+ There is a deliberate lack of full specification around
190
+ rack.hijack_io, as semantics will change from server to server.
191
+ Users are encouraged to utilize this API with a knowledge of their
192
+ server choice, and servers may extend the functionality of
193
+ hijack_io to provide additional features to users. The purpose of
194
+ rack.hijack is for Rack to "get out of the way", as such, Rack only
195
+ provides the minimum of specification and support.
196
+ If rack.hijack? is false, then rack.hijack should not be set.
197
+ If rack.hijack? is false, then rack.hijack_io should not be set.
198
+ ==== Response (after headers)
199
+ It is also possible to hijack a response after the status and headers
200
+ have been sent.
201
+ In order to do this, an application may set the special header
202
+ <tt>rack.hijack</tt> to an object that responds to <tt>call</tt>
203
+ accepting an argument that conforms to the <tt>rack.hijack_io</tt>
204
+ protocol.
205
+ After the headers have been sent, and this hijack callback has been
206
+ called, the application is now responsible for the remaining lifecycle
207
+ of the IO. The application is also responsible for maintaining HTTP
208
+ semantics. Of specific note, in almost all cases in the current SPEC,
209
+ applications will have wanted to specify the header Connection:close in
210
+ HTTP/1.1, and not Connection:keep-alive, as there is no protocol for
211
+ returning hijacked sockets to the web server. For that purpose, use the
212
+ body streaming API instead (progressively yielding strings via each).
213
+ Servers must ignore the <tt>body</tt> part of the response tuple when
214
+ the <tt>rack.hijack</tt> response API is in use.
215
+ The special response header <tt>rack.hijack</tt> must only be set
216
+ if the request env has <tt>rack.hijack?</tt> <tt>true</tt>.
217
+ ==== Conventions
218
+ * Middleware should not use hijack unless it is handling the whole
219
+ response.
220
+ * Middleware may wrap the IO object for the response pattern.
221
+ * Middleware should not wrap the IO object for the request pattern. The
222
+ request pattern is intended to provide the hijacker with "raw tcp".
131
223
  == The Response
132
224
  === The Status
133
225
  This is an HTTP status. When parsed as integer (+to_i+), it must be
134
226
  greater than or equal to 100.
135
227
  === The Headers
136
228
  The header must respond to +each+, and yield values of key and value.
229
+ Special headers starting "rack." are for communicating with the
230
+ server, and must not be sent back to the client.
137
231
  The header keys must be Strings.
138
- The header must not contain a +Status+ key,
139
- contain keys with <tt>:</tt> or newlines in their name,
140
- contain keys names that end in <tt>-</tt> or <tt>_</tt>,
141
- but only contain keys that consist of
142
- letters, digits, <tt>_</tt> or <tt>-</tt> and start with a letter.
232
+ The header must not contain a +Status+ key.
233
+ The header must conform to RFC7230 token specification, i.e. cannot
234
+ contain non-printable ASCII, DQUOTE or "(),/:;<=>?@[\]{}".
143
235
  The values of the header must be Strings,
144
236
  consisting of lines (for multiple header values, e.g. multiple
145
- <tt>Set-Cookie</tt> values) seperated by "\n".
237
+ <tt>Set-Cookie</tt> values) separated by "\\n".
146
238
  The lines must not contain characters below 037.
147
239
  === The Content-Type
148
- There must be a <tt>Content-Type</tt>, except when the
149
- +Status+ is 1xx, 204 or 304, in which case there must be none
150
- given.
240
+ There must not be a <tt>Content-Type</tt>, when the +Status+ is 1xx,
241
+ 204, 205 or 304.
151
242
  === The Content-Length
152
243
  There must not be a <tt>Content-Length</tt> header when the
153
- +Status+ is 1xx, 204 or 304.
244
+ +Status+ is 1xx, 204, 205 or 304.
154
245
  === The Body
155
246
  The Body must respond to +each+
156
247
  and must only yield String values.
157
248
  The Body itself should not be an instance of String, as this will
158
249
  break in Ruby 1.9.
159
- If the Body responds to +close+, it will be called after iteration.
250
+ If the Body responds to +close+, it will be called after iteration. If
251
+ the body is replaced by a middleware after action, the original body
252
+ must be closed first, if it responds to close.
160
253
  If the Body responds to +to_path+, it must return a String
161
254
  identifying the location of a file whose contents are identical
162
255
  to that produced by calling +each+; this may be used by the
data/contrib/rack.png ADDED
Binary file