rack 2.1.0 → 3.1.0

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.

Potentially problematic release.


This version of rack might be problematic. Click here for more details.

Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +377 -16
  3. data/CONTRIBUTING.md +144 -0
  4. data/MIT-LICENSE +1 -1
  5. data/README.md +328 -0
  6. data/SPEC.rdoc +365 -0
  7. data/lib/rack/auth/abstract/handler.rb +3 -1
  8. data/lib/rack/auth/abstract/request.rb +2 -2
  9. data/lib/rack/auth/basic.rb +4 -7
  10. data/lib/rack/bad_request.rb +8 -0
  11. data/lib/rack/body_proxy.rb +34 -12
  12. data/lib/rack/builder.rb +162 -59
  13. data/lib/rack/cascade.rb +24 -10
  14. data/lib/rack/common_logger.rb +43 -28
  15. data/lib/rack/conditional_get.rb +30 -25
  16. data/lib/rack/constants.rb +66 -0
  17. data/lib/rack/content_length.rb +10 -16
  18. data/lib/rack/content_type.rb +9 -7
  19. data/lib/rack/deflater.rb +78 -50
  20. data/lib/rack/directory.rb +86 -63
  21. data/lib/rack/etag.rb +14 -22
  22. data/lib/rack/events.rb +18 -17
  23. data/lib/rack/files.rb +99 -61
  24. data/lib/rack/head.rb +8 -9
  25. data/lib/rack/headers.rb +238 -0
  26. data/lib/rack/lint.rb +868 -642
  27. data/lib/rack/lock.rb +2 -6
  28. data/lib/rack/logger.rb +3 -0
  29. data/lib/rack/media_type.rb +9 -4
  30. data/lib/rack/method_override.rb +6 -2
  31. data/lib/rack/mime.rb +14 -5
  32. data/lib/rack/mock.rb +1 -253
  33. data/lib/rack/mock_request.rb +171 -0
  34. data/lib/rack/mock_response.rb +124 -0
  35. data/lib/rack/multipart/generator.rb +15 -8
  36. data/lib/rack/multipart/parser.rb +238 -107
  37. data/lib/rack/multipart/uploaded_file.rb +17 -7
  38. data/lib/rack/multipart.rb +54 -42
  39. data/lib/rack/null_logger.rb +9 -0
  40. data/lib/rack/query_parser.rb +87 -105
  41. data/lib/rack/recursive.rb +3 -1
  42. data/lib/rack/reloader.rb +0 -4
  43. data/lib/rack/request.rb +366 -135
  44. data/lib/rack/response.rb +186 -68
  45. data/lib/rack/rewindable_input.rb +24 -6
  46. data/lib/rack/runtime.rb +8 -7
  47. data/lib/rack/sendfile.rb +29 -27
  48. data/lib/rack/show_exceptions.rb +27 -12
  49. data/lib/rack/show_status.rb +21 -13
  50. data/lib/rack/static.rb +19 -12
  51. data/lib/rack/tempfile_reaper.rb +14 -5
  52. data/lib/rack/urlmap.rb +5 -6
  53. data/lib/rack/utils.rb +274 -260
  54. data/lib/rack/version.rb +21 -0
  55. data/lib/rack.rb +18 -103
  56. metadata +25 -52
  57. data/README.rdoc +0 -262
  58. data/Rakefile +0 -123
  59. data/SPEC +0 -263
  60. data/bin/rackup +0 -5
  61. data/contrib/rack.png +0 -0
  62. data/contrib/rack.svg +0 -150
  63. data/contrib/rack_logo.svg +0 -164
  64. data/contrib/rdoc.css +0 -412
  65. data/example/lobster.ru +0 -6
  66. data/example/protectedlobster.rb +0 -16
  67. data/example/protectedlobster.ru +0 -10
  68. data/lib/rack/auth/digest/md5.rb +0 -131
  69. data/lib/rack/auth/digest/nonce.rb +0 -54
  70. data/lib/rack/auth/digest/params.rb +0 -54
  71. data/lib/rack/auth/digest/request.rb +0 -43
  72. data/lib/rack/chunked.rb +0 -92
  73. data/lib/rack/core_ext/regexp.rb +0 -14
  74. data/lib/rack/file.rb +0 -8
  75. data/lib/rack/handler/cgi.rb +0 -62
  76. data/lib/rack/handler/fastcgi.rb +0 -102
  77. data/lib/rack/handler/lsws.rb +0 -63
  78. data/lib/rack/handler/scgi.rb +0 -73
  79. data/lib/rack/handler/thin.rb +0 -38
  80. data/lib/rack/handler/webrick.rb +0 -122
  81. data/lib/rack/handler.rb +0 -104
  82. data/lib/rack/lobster.rb +0 -72
  83. data/lib/rack/server.rb +0 -467
  84. data/lib/rack/session/abstract/id.rb +0 -528
  85. data/lib/rack/session/cookie.rb +0 -205
  86. data/lib/rack/session/memcache.rb +0 -10
  87. data/lib/rack/session/pool.rb +0 -85
  88. data/rack.gemspec +0 -44
data/README.md ADDED
@@ -0,0 +1,328 @@
1
+ # ![Rack](contrib/logo.webp)
2
+
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.
7
+
8
+ The exact details of this are described in the [Rack Specification], which all
9
+ Rack applications should conform to.
10
+
11
+ ## Version support
12
+
13
+ | Version | Support |
14
+ |----------|------------------------------------|
15
+ | 3.0.x | Bug fixes and security patches. |
16
+ | 2.2.x | Security patches only. |
17
+ | <= 2.1.x | End of support. |
18
+
19
+ Please see the [Security Policy] for more information.
20
+
21
+ ## Rack 3.0
22
+
23
+ This is the latest version of Rack. It contains API improvements but also some
24
+ breaking changes. Please check the [Upgrade Guide](UPGRADE-GUIDE.md) for more
25
+ details about migrating servers, middlewares and applications designed for Rack 2
26
+ to Rack 3. For detailed information on specific changes, check the [Change Log](CHANGELOG.md).
27
+
28
+ ## Rack 2.2
29
+
30
+ This version of Rack is receiving security patches only, and effort should be
31
+ made to move to Rack 3.
32
+
33
+ Starting in Ruby 3.4 the `base64` dependency will no longer be a default gem,
34
+ and may cause a warning or error about `base64` being missing. To correct this,
35
+ add `base64` as a dependency to your project.
36
+
37
+ ## Installation
38
+
39
+ Add the rack gem to your application bundle, or follow the instructions provided
40
+ by a [supported web framework](#supported-web-frameworks):
41
+
42
+ ```bash
43
+ # Install it generally:
44
+ $ gem install rack
45
+
46
+ # or, add it to your current application gemfile:
47
+ $ bundle add rack
48
+ ```
49
+
50
+ If you need features from `Rack::Session` or `bin/rackup` please add those gems separately.
51
+
52
+ ```bash
53
+ $ gem install rack-session rackup
54
+ ```
55
+
56
+ ## Usage
57
+
58
+ Create a file called `config.ru` with the following contents:
59
+
60
+ ```ruby
61
+ run do |env|
62
+ [200, {}, ["Hello World"]]
63
+ end
64
+ ```
65
+
66
+ Run this using the rackup gem or another [supported web
67
+ server](#supported-web-servers).
68
+
69
+ ```bash
70
+ $ gem install rackup
71
+ $ rackup
72
+ $ curl http://localhost:9292
73
+ Hello World
74
+ ```
75
+
76
+ ## Supported web servers
77
+
78
+ Rack is supported by a wide range of servers, including:
79
+
80
+ * [Agoo](https://github.com/ohler55/agoo)
81
+ * [Falcon](https://github.com/socketry/falcon)
82
+ * [Iodine](https://github.com/boazsegev/iodine)
83
+ * [NGINX Unit](https://unit.nginx.org/)
84
+ * [Phusion Passenger](https://www.phusionpassenger.com/) (which is mod_rack for
85
+ Apache and for nginx)
86
+ * [Puma](https://puma.io/)
87
+ * [Thin](https://github.com/macournoyer/thin)
88
+ * [Unicorn](https://yhbt.net/unicorn/)
89
+ * [uWSGI](https://uwsgi-docs.readthedocs.io/en/latest/)
90
+ * [Lamby](https://lamby.custominktech.com) (for AWS Lambda)
91
+
92
+ You will need to consult the server documentation to find out what features and
93
+ limitations they may have. In general, any valid Rack app will run the same on
94
+ all these servers, without changing anything.
95
+
96
+ ### Rackup
97
+
98
+ Rack provides a separate gem, [rackup](https://github.com/rack/rackup) which is
99
+ a generic interface for running a Rack application on supported servers, which
100
+ include `WEBRick`, `Puma`, `Falcon` and others.
101
+
102
+ ## Supported web frameworks
103
+
104
+ These frameworks and many others support the [Rack Specification]:
105
+
106
+ * [Camping](https://github.com/camping/camping)
107
+ * [Hanami](https://hanamirb.org/)
108
+ * [Ramaze](https://github.com/ramaze/ramaze)
109
+ * [Padrino](https://padrinorb.com/)
110
+ * [Roda](https://github.com/jeremyevans/roda)
111
+ * [Ruby on Rails](https://rubyonrails.org/)
112
+ * [Rum](https://github.com/leahneukirchen/rum)
113
+ * [Sinatra](https://sinatrarb.com/)
114
+ * [Utopia](https://github.com/socketry/utopia)
115
+ * [WABuR](https://github.com/ohler55/wabur)
116
+
117
+ ## Available middleware shipped with Rack
118
+
119
+ Between the server and the framework, Rack can be customized to your
120
+ applications needs using middleware. Rack itself ships with the following
121
+ middleware:
122
+
123
+ * `Rack::CommonLogger` for creating Apache-style logfiles.
124
+ * `Rack::ConditionalGet` for returning [Not
125
+ Modified](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/304)
126
+ responses when the response has not changed.
127
+ * `Rack::Config` for modifying the environment before processing the request.
128
+ * `Rack::ContentLength` for setting a `content-length` header based on body
129
+ size.
130
+ * `Rack::ContentType` for setting a default `content-type` header for responses.
131
+ * `Rack::Deflater` for compressing responses with gzip.
132
+ * `Rack::ETag` for setting `etag` header on bodies that can be buffered.
133
+ * `Rack::Events` for providing easy hooks when a request is received and when
134
+ the response is sent.
135
+ * `Rack::Files` for serving static files.
136
+ * `Rack::Head` for returning an empty body for HEAD requests.
137
+ * `Rack::Lint` for checking conformance to the [Rack Specification].
138
+ * `Rack::Lock` for serializing requests using a mutex.
139
+ * `Rack::Logger` for setting a logger to handle logging errors.
140
+ * `Rack::MethodOverride` for modifying the request method based on a submitted
141
+ parameter.
142
+ * `Rack::Recursive` for including data from other paths in the application, and
143
+ for performing internal redirects.
144
+ * `Rack::Reloader` for reloading files if they have been modified.
145
+ * `Rack::Runtime` for including a response header with the time taken to process
146
+ the request.
147
+ * `Rack::Sendfile` for working with web servers that can use optimized file
148
+ serving for file system paths.
149
+ * `Rack::ShowException` for catching unhandled exceptions and presenting them in
150
+ a nice and helpful way with clickable backtrace.
151
+ * `Rack::ShowStatus` for using nice error pages for empty client error
152
+ responses.
153
+ * `Rack::Static` for more configurable serving of static files.
154
+ * `Rack::TempfileReaper` for removing temporary files creating during a request.
155
+
156
+ All these components use the same interface, which is described in detail in the
157
+ [Rack Specification]. These optional components can be used in any way you wish.
158
+
159
+ ### Convenience interfaces
160
+
161
+ If you want to develop outside of existing frameworks, implement your own ones,
162
+ or develop middleware, Rack provides many helpers to create Rack applications
163
+ quickly and without doing the same web stuff all over:
164
+
165
+ * `Rack::Request` which also provides query string parsing and multipart
166
+ handling.
167
+ * `Rack::Response` for convenient generation of HTTP replies and cookie
168
+ handling.
169
+ * `Rack::MockRequest` and `Rack::MockResponse` for efficient and quick testing
170
+ of Rack application without real HTTP round-trips.
171
+ * `Rack::Cascade` for trying additional Rack applications if an application
172
+ returns a not found or method not supported response.
173
+ * `Rack::Directory` for serving files under a given directory, with directory
174
+ indexes.
175
+ * `Rack::MediaType` for parsing content-type headers.
176
+ * `Rack::Mime` for determining content-type based on file extension.
177
+ * `Rack::RewindableInput` for making any IO object rewindable, using a temporary
178
+ file buffer.
179
+ * `Rack::URLMap` to route to multiple applications inside the same process.
180
+
181
+ ## Configuration
182
+
183
+ Rack exposes several configuration parameters to control various features of the
184
+ implementation.
185
+
186
+ ### `param_depth_limit`
187
+
188
+ ```ruby
189
+ Rack::Utils.param_depth_limit = 32 # default
190
+ ```
191
+
192
+ The maximum amount of nesting allowed in parameters. For example, if set to 3,
193
+ this query string would be allowed:
194
+
195
+ ```
196
+ ?a[b][c]=d
197
+ ```
198
+
199
+ but this query string would not be allowed:
200
+
201
+ ```
202
+ ?a[b][c][d]=e
203
+ ```
204
+
205
+ Limiting the depth prevents a possible stack overflow when parsing parameters.
206
+
207
+ ### `multipart_file_limit`
208
+
209
+ ```ruby
210
+ Rack::Utils.multipart_file_limit = 128 # default
211
+ ```
212
+
213
+ The maximum number of parts with a filename a request can contain. Accepting
214
+ too many parts can lead to the server running out of file handles.
215
+
216
+ The default is 128, which means that a single request can't upload more than 128
217
+ files at once. Set to 0 for no limit.
218
+
219
+ Can also be set via the `RACK_MULTIPART_FILE_LIMIT` environment variable.
220
+
221
+ (This is also aliased as `multipart_part_limit` and `RACK_MULTIPART_PART_LIMIT` for compatibility)
222
+
223
+
224
+ ### `multipart_total_part_limit`
225
+
226
+ The maximum total number of parts a request can contain of any type, including
227
+ both file and non-file form fields.
228
+
229
+ The default is 4096, which means that a single request can't contain more than
230
+ 4096 parts.
231
+
232
+ Set to 0 for no limit.
233
+
234
+ Can also be set via the `RACK_MULTIPART_TOTAL_PART_LIMIT` environment variable.
235
+
236
+
237
+ ## Changelog
238
+
239
+ See [CHANGELOG.md](CHANGELOG.md).
240
+
241
+ ## Contributing
242
+
243
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for specific details about how to make a
244
+ contribution to Rack.
245
+
246
+ Please post bugs, suggestions and patches to [GitHub
247
+ Issues](https://github.com/rack/rack/issues).
248
+
249
+ Please check our [Security Policy](https://github.com/rack/rack/security/policy)
250
+ for responsible disclosure and security bug reporting process. Due to wide usage
251
+ of the library, it is strongly preferred that we manage timing in order to
252
+ provide viable patches at the time of disclosure. Your assistance in this matter
253
+ is greatly appreciated.
254
+
255
+ ## See Also
256
+
257
+ ### `rack-contrib`
258
+
259
+ The plethora of useful middleware created the need for a project that collects
260
+ fresh Rack middleware. `rack-contrib` includes a variety of add-on components
261
+ for Rack and it is easy to contribute new modules.
262
+
263
+ * https://github.com/rack/rack-contrib
264
+
265
+ ### `rack-session`
266
+
267
+ Provides convenient session management for Rack.
268
+
269
+ * https://github.com/rack/rack-session
270
+
271
+ ## Thanks
272
+
273
+ The Rack Core Team, consisting of
274
+
275
+ * Aaron Patterson [tenderlove](https://github.com/tenderlove)
276
+ * Samuel Williams [ioquatix](https://github.com/ioquatix)
277
+ * Jeremy Evans [jeremyevans](https://github.com/jeremyevans)
278
+ * Eileen Uchitelle [eileencodes](https://github.com/eileencodes)
279
+ * Matthew Draper [matthewd](https://github.com/matthewd)
280
+ * Rafael França [rafaelfranca](https://github.com/rafaelfranca)
281
+
282
+ and the Rack Alumni
283
+
284
+ * Ryan Tomayko [rtomayko](https://github.com/rtomayko)
285
+ * Scytrin dai Kinthra [scytrin](https://github.com/scytrin)
286
+ * Leah Neukirchen [leahneukirchen](https://github.com/leahneukirchen)
287
+ * James Tucker [raggi](https://github.com/raggi)
288
+ * Josh Peek [josh](https://github.com/josh)
289
+ * José Valim [josevalim](https://github.com/josevalim)
290
+ * Michael Fellinger [manveru](https://github.com/manveru)
291
+ * Santiago Pastorino [spastorino](https://github.com/spastorino)
292
+ * Konstantin Haase [rkh](https://github.com/rkh)
293
+
294
+ would like to thank:
295
+
296
+ * Adrian Madrid, for the LiteSpeed handler.
297
+ * Christoffer Sawicki, for the first Rails adapter and `Rack::Deflater`.
298
+ * Tim Fletcher, for the HTTP authentication code.
299
+ * Luc Heinrich for the Cookie sessions, the static file handler and bugfixes.
300
+ * Armin Ronacher, for the logo and racktools.
301
+ * Alex Beregszaszi, Alexander Kahn, Anil Wadghule, Aredridel, Ben Alpert, Dan
302
+ Kubb, Daniel Roethlisberger, Matt Todd, Tom Robinson, Phil Hagelberg, S. Brent
303
+ Faulkner, Bosko Milekic, Daniel Rodríguez Troitiño, Genki Takiuchi, Geoffrey
304
+ Grosenbach, Julien Sanchez, Kamal Fariz Mahyuddin, Masayoshi Takahashi,
305
+ Patrick Aljordm, Mig, Kazuhiro Nishiyama, Jon Bardin, Konstantin Haase, Larry
306
+ Siden, Matias Korhonen, Sam Ruby, Simon Chiang, Tim Connor, Timur Batyrshin,
307
+ and Zach Brock for bug fixing and other improvements.
308
+ * Eric Wong, Hongli Lai, Jeremy Kemper for their continuous support and API
309
+ improvements.
310
+ * Yehuda Katz and Carl Lerche for refactoring rackup.
311
+ * Brian Candler, for `Rack::ContentType`.
312
+ * Graham Batty, for improved handler loading.
313
+ * Stephen Bannasch, for bug reports and documentation.
314
+ * Gary Wright, for proposing a better `Rack::Response` interface.
315
+ * Jonathan Buch, for improvements regarding `Rack::Response`.
316
+ * Armin Röhrl, for tracking down bugs in the Cookie generator.
317
+ * Alexander Kellett for testing the Gem and reviewing the announcement.
318
+ * Marcus Rückert, for help with configuring and debugging lighttpd.
319
+ * The WSGI team for the well-done and documented work they've done and Rack
320
+ builds up on.
321
+ * All bug reporters and patch contributors not mentioned above.
322
+
323
+ ## License
324
+
325
+ Rack is released under the [MIT License](MIT-LICENSE).
326
+
327
+ [Rack Specification]: SPEC.rdoc
328
+ [Security Policy]: SECURITY.md
data/SPEC.rdoc ADDED
@@ -0,0 +1,365 @@
1
+ This specification aims to formalize the Rack protocol. You
2
+ can (and should) use Rack::Lint to enforce it.
3
+
4
+ When you develop middleware, be sure to add a Lint before and
5
+ after to catch all mistakes.
6
+
7
+ = Rack applications
8
+
9
+ A Rack application is a Ruby object (not a class) that
10
+ responds to +call+.
11
+ It takes exactly one argument, the *environment*
12
+ and returns a non-frozen Array of exactly three values:
13
+ The *status*,
14
+ the *headers*,
15
+ and the *body*.
16
+
17
+ == The Environment
18
+
19
+ The environment must be an unfrozen instance of Hash that includes
20
+ CGI-like headers. The Rack application is free to modify the
21
+ environment.
22
+
23
+ The environment is required to include these variables
24
+ (adopted from {PEP 333}[https://peps.python.org/pep-0333/]), except when they'd be empty, but see
25
+ below.
26
+ <tt>REQUEST_METHOD</tt>:: The HTTP request method, such as
27
+ "GET" or "POST". This cannot ever
28
+ be an empty string, and so is
29
+ always required.
30
+ <tt>SCRIPT_NAME</tt>:: The initial portion of the request
31
+ URL's "path" that corresponds to the
32
+ application object, so that the
33
+ application knows its virtual
34
+ "location". This may be an empty
35
+ string, if the application corresponds
36
+ to the "root" of the server.
37
+ <tt>PATH_INFO</tt>:: The remainder of the request URL's
38
+ "path", designating the virtual
39
+ "location" of the request's target
40
+ within the application. This may be an
41
+ empty string, if the request URL targets
42
+ the application root and does not have a
43
+ trailing slash. This value may be
44
+ percent-encoded when originating from
45
+ a URL.
46
+ <tt>QUERY_STRING</tt>:: The portion of the request URL that
47
+ follows the <tt>?</tt>, if any. May be
48
+ empty, but is always required!
49
+ <tt>SERVER_NAME</tt>:: When combined with <tt>SCRIPT_NAME</tt> and
50
+ <tt>PATH_INFO</tt>, these variables can be
51
+ used to complete the URL. Note, however,
52
+ that <tt>HTTP_HOST</tt>, if present,
53
+ should be used in preference to
54
+ <tt>SERVER_NAME</tt> for reconstructing
55
+ the request URL.
56
+ <tt>SERVER_NAME</tt> can never be an empty
57
+ string, and so is always required.
58
+ <tt>SERVER_PORT</tt>:: An optional +Integer+ which is the port the
59
+ server is running on. Should be specified if
60
+ the server is running on a non-standard port.
61
+ <tt>SERVER_PROTOCOL</tt>:: A string representing the HTTP version used
62
+ for the request.
63
+ <tt>HTTP_</tt> Variables:: Variables corresponding to the
64
+ client-supplied HTTP request
65
+ headers (i.e., variables whose
66
+ names begin with <tt>HTTP_</tt>). The
67
+ presence or absence of these
68
+ variables should correspond with
69
+ the presence or absence of the
70
+ appropriate HTTP header in the
71
+ request. See
72
+ {RFC3875 section 4.1.18}[https://tools.ietf.org/html/rfc3875#section-4.1.18]
73
+ for specific behavior.
74
+ In addition to this, the Rack environment must include these
75
+ Rack-specific variables:
76
+ <tt>rack.url_scheme</tt>:: +http+ or +https+, depending on the
77
+ request URL.
78
+ <tt>rack.input</tt>:: See below, the input stream.
79
+ <tt>rack.errors</tt>:: See below, the error stream.
80
+ <tt>rack.hijack?</tt>:: See below, if present and true, indicates
81
+ that the server supports partial hijacking.
82
+ <tt>rack.hijack</tt>:: See below, if present, an object responding
83
+ to +call+ that is used to perform a full
84
+ hijack.
85
+ <tt>rack.protocol</tt>:: An optional +Array+ of +String+, containing
86
+ the protocols advertised by the client in
87
+ the +upgrade+ header (HTTP/1) or the
88
+ +:protocol+ pseudo-header (HTTP/2).
89
+ Additional environment specifications have approved to
90
+ standardized middleware APIs. None of these are required to
91
+ be implemented by the server.
92
+ <tt>rack.session</tt>:: A hash-like interface for storing
93
+ request session data.
94
+ The store must implement:
95
+ store(key, value) (aliased as []=);
96
+ fetch(key, default = nil) (aliased as []);
97
+ delete(key);
98
+ clear;
99
+ to_hash (returning unfrozen Hash instance);
100
+ <tt>rack.logger</tt>:: A common object interface for logging messages.
101
+ The object must implement:
102
+ info(message, &block)
103
+ debug(message, &block)
104
+ warn(message, &block)
105
+ error(message, &block)
106
+ fatal(message, &block)
107
+ <tt>rack.multipart.buffer_size</tt>:: An Integer hint to the multipart parser as to what chunk size to use for reads and writes.
108
+ <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.
109
+ The server or the application can store their own data in the
110
+ environment, too. The keys must contain at least one dot,
111
+ and should be prefixed uniquely. The prefix <tt>rack.</tt>
112
+ is reserved for use with the Rack core distribution and other
113
+ accepted specifications and must not be used otherwise.
114
+
115
+ The <tt>SERVER_PORT</tt> must be an Integer if set.
116
+ The <tt>SERVER_NAME</tt> must be a valid authority as defined by RFC7540.
117
+ The <tt>HTTP_HOST</tt> must be a valid authority as defined by RFC7540.
118
+ The <tt>SERVER_PROTOCOL</tt> must match the regexp <tt>HTTP/\d(\.\d)?</tt>.
119
+ The environment must not contain the keys
120
+ <tt>HTTP_CONTENT_TYPE</tt> or <tt>HTTP_CONTENT_LENGTH</tt>
121
+ (use the versions without <tt>HTTP_</tt>).
122
+ The CGI keys (named without a period) must have String values.
123
+ If the string values for CGI keys contain non-ASCII characters,
124
+ they should use ASCII-8BIT encoding.
125
+ There are the following restrictions:
126
+ * <tt>rack.url_scheme</tt> must either be +http+ or +https+.
127
+ * There may be a valid input stream in <tt>rack.input</tt>.
128
+ * There must be a valid error stream in <tt>rack.errors</tt>.
129
+ * There may be a valid hijack callback in <tt>rack.hijack</tt>
130
+ * There may be a valid early hints callback in <tt>rack.early_hints</tt>
131
+ * The <tt>REQUEST_METHOD</tt> must be a valid token.
132
+ * The <tt>SCRIPT_NAME</tt>, if non-empty, must start with <tt>/</tt>
133
+ * The <tt>PATH_INFO</tt>, if provided, must be a valid request target.
134
+ * Only <tt>OPTIONS</tt> requests may have <tt>PATH_INFO</tt> set to <tt>*</tt> (asterisk-form).
135
+ * Only <tt>CONNECT</tt> requests may have <tt>PATH_INFO</tt> set to an authority (authority-form). Note that in HTTP/2+, the authority-form is not a valid request target.
136
+ * <tt>CONNECT</tt> and <tt>OPTIONS</tt> requests must not have <tt>PATH_INFO</tt> set to a URI (absolute-form).
137
+ * Otherwise, <tt>PATH_INFO</tt> must start with a <tt>/</tt> and must not include a fragment part starting with '#' (origin-form).
138
+ * The <tt>CONTENT_LENGTH</tt>, if given, must consist of digits only.
139
+ * One of <tt>SCRIPT_NAME</tt> or <tt>PATH_INFO</tt> must be
140
+ set. <tt>PATH_INFO</tt> should be <tt>/</tt> if
141
+ <tt>SCRIPT_NAME</tt> is empty.
142
+ <tt>SCRIPT_NAME</tt> never should be <tt>/</tt>, but instead be empty.
143
+ <tt>rack.response_finished</tt>:: An array of callables run by the server after the response has been
144
+ processed. This would typically be invoked after sending the response to the client, but it could also be
145
+ invoked if an error occurs while generating the response or sending the response; in that case, the error
146
+ argument will be a subclass of +Exception+.
147
+ The callables are invoked with +env, status, headers, error+ arguments and should not raise any
148
+ exceptions. They should be invoked in reverse order of registration.
149
+
150
+ === The Input Stream
151
+
152
+ The input stream is an IO-like object which contains the raw HTTP
153
+ POST data.
154
+ When applicable, its external encoding must be "ASCII-8BIT" and it
155
+ must be opened in binary mode.
156
+ The input stream must respond to +gets+, +each+, and +read+.
157
+ * +gets+ must be called without arguments and return a string,
158
+ or +nil+ on EOF.
159
+ * +read+ behaves like <tt>IO#read</tt>.
160
+ Its signature is <tt>read([length, [buffer]])</tt>.
161
+
162
+ If given, +length+ must be a non-negative Integer (>= 0) or +nil+,
163
+ and +buffer+ must be a String and may not be nil.
164
+
165
+ If +length+ is given and not nil, then this method reads at most
166
+ +length+ bytes from the input stream.
167
+
168
+ If +length+ is not given or nil, then this method reads
169
+ all data until EOF.
170
+
171
+ When EOF is reached, this method returns nil if +length+ is given
172
+ and not nil, or "" if +length+ is not given or is nil.
173
+
174
+ If +buffer+ is given, then the read data will be placed
175
+ into +buffer+ instead of a newly created String object.
176
+ * +each+ must be called without arguments and only yield Strings.
177
+ * +close+ can be called on the input stream to indicate that
178
+ any remaining input is not needed.
179
+
180
+ === The Error Stream
181
+
182
+ The error stream must respond to +puts+, +write+ and +flush+.
183
+ * +puts+ must be called with a single argument that responds to +to_s+.
184
+ * +write+ must be called with a single argument that is a String.
185
+ * +flush+ must be called without arguments and must be called
186
+ in order to make the error appear for sure.
187
+ * +close+ must never be called on the error stream.
188
+
189
+ === Hijacking
190
+
191
+ The hijacking interfaces provides a means for an application to take
192
+ control of the HTTP connection. There are two distinct hijack
193
+ interfaces: full hijacking where the application takes over the raw
194
+ connection, and partial hijacking where the application takes over
195
+ just the response body stream. In both cases, the application is
196
+ responsible for closing the hijacked stream.
197
+
198
+ Full hijacking only works with HTTP/1. Partial hijacking is functionally
199
+ equivalent to streaming bodies, and is still optionally supported for
200
+ backwards compatibility with older Rack versions.
201
+
202
+ ==== Full Hijack
203
+
204
+ Full hijack is used to completely take over an HTTP/1 connection. It
205
+ occurs before any headers are written and causes the request to
206
+ ignores any response generated by the application.
207
+
208
+ It is intended to be used when applications need access to raw HTTP/1
209
+ connection.
210
+
211
+ If +rack.hijack+ is present in +env+, it must respond to +call+
212
+ and return an +IO+ instance which can be used to read and write
213
+ to the underlying connection using HTTP/1 semantics and
214
+ formatting.
215
+
216
+ ==== Partial Hijack
217
+
218
+ Partial hijack is used for bi-directional streaming of the request and
219
+ response body. It occurs after the status and headers are written by
220
+ the server and causes the server to ignore the Body of the response.
221
+
222
+ It is intended to be used when applications need bi-directional
223
+ streaming.
224
+
225
+ If +rack.hijack?+ is present in +env+ and truthy,
226
+ an application may set the special response header +rack.hijack+
227
+ to an object that responds to +call+,
228
+ accepting a +stream+ argument.
229
+
230
+ After the response status and headers have been sent, this hijack
231
+ callback will be invoked with a +stream+ argument which follows the
232
+ same interface as outlined in "Streaming Body". Servers must
233
+ ignore the +body+ part of the response tuple when the
234
+ +rack.hijack+ response header is present. Using an empty +Array+
235
+ instance is recommended.
236
+
237
+ The special response header +rack.hijack+ must only be set
238
+ if the request +env+ has a truthy +rack.hijack?+.
239
+
240
+ === Early Hints
241
+
242
+ The application or any middleware may call the <tt>rack.early_hints</tt>
243
+ with an object which would be valid as the headers of a Rack response.
244
+
245
+ If <tt>rack.early_hints</tt> is present, it must respond to #call.
246
+ If <tt>rack.early_hints</tt> is called, it must be called with
247
+ valid Rack response headers.
248
+
249
+ == The Response
250
+
251
+ === The Status
252
+
253
+ This is an HTTP status. It must be an Integer greater than or equal to
254
+ 100.
255
+
256
+ === The Headers
257
+
258
+ The headers must be a unfrozen Hash.
259
+ The header keys must be Strings.
260
+ Special headers starting "rack." are for communicating with the
261
+ server, and must not be sent back to the client.
262
+ The header must not contain a +Status+ key.
263
+ Header keys must conform to RFC7230 token specification, i.e. cannot
264
+ contain non-printable ASCII, DQUOTE or "(),/:;<=>?@[\]{}".
265
+ Header keys must not contain uppercase ASCII characters (A-Z).
266
+ Header values must be either a String instance,
267
+ or an Array of String instances,
268
+ such that each String instance must not contain characters below 037.
269
+
270
+ ==== The +content-type+ Header
271
+
272
+ There must not be a <tt>content-type</tt> header key when the +Status+ is 1xx,
273
+ 204, or 304.
274
+
275
+ ==== The +content-length+ Header
276
+
277
+ There must not be a <tt>content-length</tt> header key when the
278
+ +Status+ is 1xx, 204, or 304.
279
+
280
+ ==== The +rack.protocol+ Header
281
+
282
+ If the +rack.protocol+ header is present, it must be a +String+, and
283
+ must be one of the values from the +rack.protocol+ array from the
284
+ environment.
285
+
286
+ Setting this value informs the server that it should perform a
287
+ connection upgrade. In HTTP/1, this is done using the +upgrade+
288
+ header. In HTTP/2, this is done by accepting the request.
289
+
290
+ === The Body
291
+
292
+ The Body is typically an +Array+ of +String+ instances, an enumerable
293
+ that yields +String+ instances, a +Proc+ instance, or a File-like
294
+ object.
295
+
296
+ The Body must respond to +each+ or +call+. It may optionally respond
297
+ to +to_path+ or +to_ary+. A Body that responds to +each+ is considered
298
+ to be an Enumerable Body. A Body that responds to +call+ is considered
299
+ to be a Streaming Body.
300
+
301
+ A Body that responds to both +each+ and +call+ must be treated as an
302
+ Enumerable Body, not a Streaming Body. If it responds to +each+, you
303
+ must call +each+ and not +call+. If the Body doesn't respond to
304
+ +each+, then you can assume it responds to +call+.
305
+
306
+ The Body must either be consumed or returned. The Body is consumed by
307
+ optionally calling either +each+ or +call+.
308
+ Then, if the Body responds to +close+, it must be called to release
309
+ any resources associated with the generation of the body.
310
+ In other words, +close+ must always be called at least once; typically
311
+ after the web server has sent the response to the client, but also in
312
+ cases where the Rack application makes internal/virtual requests and
313
+ discards the response.
314
+
315
+
316
+ After calling +close+, the Body is considered closed and should not
317
+ be consumed again.
318
+ If the original Body is replaced by a new Body, the new Body must
319
+ also consume the original Body by calling +close+ if possible.
320
+
321
+ If the Body responds to +to_path+, it must return a +String+
322
+ path for the local file system whose contents are identical
323
+ to that produced by calling +each+; this may be used by the
324
+ server as an alternative, possibly more efficient way to
325
+ transport the response. The +to_path+ method does not consume
326
+ the body.
327
+
328
+ ==== Enumerable Body
329
+
330
+ The Enumerable Body must respond to +each+.
331
+ It must only be called once.
332
+ It must not be called after being closed,
333
+ and must only yield String values.
334
+
335
+ Middleware must not call +each+ directly on the Body.
336
+ Instead, middleware can return a new Body that calls +each+ on the
337
+ original Body, yielding at least once per iteration.
338
+
339
+ If the Body responds to +to_ary+, it must return an +Array+ whose
340
+ contents are identical to that produced by calling +each+.
341
+ Middleware may call +to_ary+ directly on the Body and return a new
342
+ Body in its place. In other words, middleware can only process the
343
+ Body directly if it responds to +to_ary+. If the Body responds to both
344
+ +to_ary+ and +close+, its implementation of +to_ary+ must call
345
+ +close+.
346
+
347
+ ==== Streaming Body
348
+
349
+ The Streaming Body must respond to +call+.
350
+ It must only be called once.
351
+ It must not be called after being closed.
352
+ It takes a +stream+ argument.
353
+
354
+ The +stream+ argument must implement:
355
+ <tt>read, write, <<, flush, close, close_read, close_write, closed?</tt>
356
+
357
+ The semantics of these IO methods must be a best effort match to
358
+ those of a normal Ruby IO or Socket object, using standard arguments
359
+ and raising standard exceptions. Servers are encouraged to simply
360
+ pass on real IO objects, although it is recognized that this approach
361
+ is not directly compatible with HTTP/2.
362
+
363
+ == Thanks
364
+ Some parts of this specification are adopted from {PEP 333 – Python Web Server Gateway Interface v1.0}[https://peps.python.org/pep-0333/]
365
+ I'd like to thank everyone involved in that effort.