rack 2.2.17 → 3.2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +501 -70
- data/CONTRIBUTING.md +63 -55
- data/MIT-LICENSE +1 -1
- data/README.md +376 -0
- data/SPEC.rdoc +243 -277
- data/lib/rack/auth/abstract/handler.rb +3 -1
- data/lib/rack/auth/abstract/request.rb +5 -1
- data/lib/rack/auth/basic.rb +1 -3
- data/lib/rack/bad_request.rb +8 -0
- data/lib/rack/body_proxy.rb +21 -3
- data/lib/rack/builder.rb +108 -69
- data/lib/rack/cascade.rb +2 -3
- data/lib/rack/common_logger.rb +22 -17
- data/lib/rack/conditional_get.rb +20 -16
- data/lib/rack/constants.rb +68 -0
- data/lib/rack/content_length.rb +12 -16
- data/lib/rack/content_type.rb +8 -5
- data/lib/rack/deflater.rb +40 -26
- data/lib/rack/directory.rb +9 -3
- data/lib/rack/etag.rb +17 -23
- data/lib/rack/events.rb +4 -0
- data/lib/rack/files.rb +15 -17
- data/lib/rack/head.rb +8 -8
- data/lib/rack/headers.rb +238 -0
- data/lib/rack/lint.rb +817 -648
- data/lib/rack/lock.rb +2 -5
- data/lib/rack/media_type.rb +6 -7
- data/lib/rack/method_override.rb +5 -1
- data/lib/rack/mime.rb +14 -5
- data/lib/rack/mock.rb +1 -300
- data/lib/rack/mock_request.rb +161 -0
- data/lib/rack/mock_response.rb +147 -0
- data/lib/rack/multipart/generator.rb +7 -5
- data/lib/rack/multipart/parser.rb +241 -95
- data/lib/rack/multipart/uploaded_file.rb +45 -4
- data/lib/rack/multipart.rb +53 -40
- data/lib/rack/null_logger.rb +9 -0
- data/lib/rack/query_parser.rb +116 -121
- data/lib/rack/recursive.rb +2 -0
- data/lib/rack/reloader.rb +0 -2
- data/lib/rack/request.rb +269 -141
- data/lib/rack/response.rb +151 -66
- data/lib/rack/rewindable_input.rb +27 -5
- data/lib/rack/runtime.rb +7 -6
- data/lib/rack/sendfile.rb +30 -25
- data/lib/rack/show_exceptions.rb +25 -6
- data/lib/rack/show_status.rb +17 -9
- data/lib/rack/static.rb +8 -8
- data/lib/rack/tempfile_reaper.rb +15 -4
- data/lib/rack/urlmap.rb +3 -1
- data/lib/rack/utils.rb +228 -238
- data/lib/rack/version.rb +3 -15
- data/lib/rack.rb +13 -90
- metadata +15 -41
- data/README.rdoc +0 -347
- data/Rakefile +0 -130
- data/bin/rackup +0 -5
- data/contrib/rack.png +0 -0
- data/contrib/rack.svg +0 -150
- data/contrib/rack_logo.svg +0 -164
- data/contrib/rdoc.css +0 -412
- data/example/lobster.ru +0 -6
- data/example/protectedlobster.rb +0 -16
- data/example/protectedlobster.ru +0 -10
- data/lib/rack/auth/digest/md5.rb +0 -131
- data/lib/rack/auth/digest/nonce.rb +0 -53
- data/lib/rack/auth/digest/params.rb +0 -54
- data/lib/rack/auth/digest/request.rb +0 -43
- data/lib/rack/chunked.rb +0 -117
- data/lib/rack/core_ext/regexp.rb +0 -14
- data/lib/rack/file.rb +0 -7
- data/lib/rack/handler/cgi.rb +0 -59
- data/lib/rack/handler/fastcgi.rb +0 -100
- data/lib/rack/handler/lsws.rb +0 -61
- data/lib/rack/handler/scgi.rb +0 -71
- data/lib/rack/handler/thin.rb +0 -36
- data/lib/rack/handler/webrick.rb +0 -129
- data/lib/rack/handler.rb +0 -104
- data/lib/rack/lobster.rb +0 -70
- data/lib/rack/logger.rb +0 -20
- data/lib/rack/server.rb +0 -466
- data/lib/rack/session/abstract/id.rb +0 -523
- data/lib/rack/session/cookie.rb +0 -203
- data/lib/rack/session/memcache.rb +0 -10
- data/lib/rack/session/pool.rb +0 -90
- data/rack.gemspec +0 -46
data/SPEC.rdoc
CHANGED
@@ -1,292 +1,258 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
A Rack application is a Ruby object (
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
The
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
The environment
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
The environment is
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
<tt>SERVER_NAME</tt
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
<tt>
|
76
|
-
|
77
|
-
<tt>
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
<tt>rack
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
<tt>
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
<tt>rack.
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
<tt>
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
* One of <tt>SCRIPT_NAME</tt> or <tt>PATH_INFO</tt> must be
|
146
|
-
set. <tt>PATH_INFO</tt> should be <tt>/</tt> if
|
147
|
-
<tt>SCRIPT_NAME</tt> is empty.
|
148
|
-
<tt>SCRIPT_NAME</tt> never should be <tt>/</tt>, but instead be empty.
|
1
|
+
= Rack Specification
|
2
|
+
|
3
|
+
This specification aims to formalize the Rack protocol. You can (and should) use +Rack::Lint+ to enforce it. When you develop middleware, be sure to test with +Rack::Lint+ to catch possible violations of this specification.
|
4
|
+
|
5
|
+
== The Application
|
6
|
+
|
7
|
+
A Rack application is a Ruby object that responds to +call+. It takes exactly one argument, the +environment+ (representing an HTTP request) and returns a non-frozen +Array+ of exactly three elements: the +status+, the +headers+, and the +body+ (representing an HTTP response).
|
8
|
+
|
9
|
+
== The Request Environment
|
10
|
+
|
11
|
+
Incoming HTTP requests are represented using an environment. The environment must be an unfrozen +Hash+. The Rack application is free to modify the environment, but the modified environment should also comply with this specification. All environment keys must be strings.
|
12
|
+
|
13
|
+
=== CGI Variables
|
14
|
+
|
15
|
+
The environment is required to include these variables, adopted from {The Common Gateway Interface}[https://datatracker.ietf.org/doc/html/rfc3875] (CGI), except when they'd be empty, but see below.
|
16
|
+
|
17
|
+
The CGI keys (named without a period) must have +String+ values and are reserved for the Rack specification. If the values for CGI keys contain non-ASCII characters, they should use <tt>ASCII-8BIT</tt> encoding.
|
18
|
+
|
19
|
+
The server and application can store their own data in the environment, too. The keys must contain at least one dot, and should be prefixed uniquely. The prefix <tt>rack.</tt> is reserved for use with the Rack specification and the classes that ship with Rack.
|
20
|
+
|
21
|
+
==== <tt>REQUEST_METHOD</tt>
|
22
|
+
|
23
|
+
The HTTP request method, such as "GET" or "POST". This cannot ever be an empty string, and so is always required.
|
24
|
+
|
25
|
+
==== <tt>SCRIPT_NAME</tt>
|
26
|
+
|
27
|
+
The initial portion of the request URL's path that corresponds to the application object, so that the application knows its virtual location. This may be an empty string, if the application corresponds to the root of the server. If non-empty, the string must start with <tt>/</tt>, but should not end with <tt>/</tt>.
|
28
|
+
|
29
|
+
In addition, <tt>SCRIPT_NAME</tt> MUST not be <tt>/</tt>, but instead be empty, and one of <tt>SCRIPT_NAME</tt> or <tt>PATH_INFO</tt> must be set, e.g. <tt>PATH_INFO</tt> can be <tt>/</tt> if <tt>SCRIPT_NAME</tt> is empty.
|
30
|
+
|
31
|
+
==== <tt>PATH_INFO</tt>
|
32
|
+
|
33
|
+
The remainder of the request URL's "path", designating the virtual "location" of the request's target within the application. This may be an empty string, if the request URL targets the application root and does not have a trailing slash. This value may be percent-encoded when originating from a URL.
|
34
|
+
|
35
|
+
The <tt>PATH_INFO</tt>, if provided, must be a valid request target or an empty string, as defined by {RFC9110}[https://datatracker.ietf.org/doc/html/rfc9110#target.resource].
|
36
|
+
* Only <tt>OPTIONS</tt> requests may have <tt>PATH_INFO</tt> set to <tt>*</tt> (asterisk-form).
|
37
|
+
* 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.
|
38
|
+
* <tt>CONNECT</tt> and <tt>OPTIONS</tt> requests must not have <tt>PATH_INFO</tt> set to a URI (absolute-form).
|
39
|
+
* Otherwise, <tt>PATH_INFO</tt> must start with a <tt>/</tt> and must not include a fragment part starting with <tt>#</tt> (origin-form).
|
40
|
+
|
41
|
+
==== <tt>QUERY_STRING</tt>
|
42
|
+
|
43
|
+
The portion of the request URL that follows the <tt>?</tt>, if any. May be empty, but is always required!
|
44
|
+
|
45
|
+
==== <tt>SERVER_NAME</tt>
|
46
|
+
|
47
|
+
Must be a valid host, as defined by {RFC3986}[https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2].
|
48
|
+
|
49
|
+
When combined with <tt>SCRIPT_NAME</tt>, <tt>PATH_INFO</tt>, and <tt>QUERY_STRING</tt>, these variables can be used to reconstruct the original the request 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.
|
50
|
+
|
51
|
+
==== <tt>SERVER_PROTOCOL</tt>
|
52
|
+
|
53
|
+
The HTTP version used for the request. It must match the regular expression <tt>HTTP\/\d(\.\d)?</tt>.
|
54
|
+
|
55
|
+
==== <tt>SERVER_PORT</tt>
|
56
|
+
|
57
|
+
The port the server is running on, if the server is running on a non-standard port. It must consist of digits only.
|
58
|
+
|
59
|
+
The standard ports are:
|
60
|
+
* 80 for HTTP
|
61
|
+
* 443 for HTTPS
|
62
|
+
|
63
|
+
==== <tt>CONTENT_TYPE</tt>
|
64
|
+
|
65
|
+
The optional MIME type of the request body, if any.
|
66
|
+
|
67
|
+
==== <tt>CONTENT_LENGTH</tt>
|
68
|
+
|
69
|
+
The length of the request body, if any. It must consist of digits only.
|
70
|
+
|
71
|
+
==== <tt>HTTP_HOST</tt>
|
72
|
+
|
73
|
+
An optional HTTP authority, as defined by {RFC9110}[https://datatracker.ietf.org/doc/html/rfc9110#name-host-and-authority].
|
74
|
+
|
75
|
+
==== <tt>HTTP_</tt> Headers
|
76
|
+
|
77
|
+
Unless specified above, the environment can contain any number of additional headers, each starting with <tt>HTTP_</tt>. The presence or absence of these variables should correspond with the presence or absence of the appropriate HTTP header in the request, and those headers have no specific interpretation or validation by the Rack specification. However, there are many standard HTTP headers that have a specific meaning in the context of a request; see {RFC3875 section 4.1.18}[https://tools.ietf.org/html/rfc3875#section-4.1.18] for more details.
|
78
|
+
|
79
|
+
For compatibility with the CGI specifiction, the environment must not contain the keys <tt>HTTP_CONTENT_TYPE</tt> or <tt>HTTP_CONTENT_LENGTH</tt>. Instead, the keys <tt>CONTENT_TYPE</tt> and <tt>CONTENT_LENGTH</tt> must be used.
|
80
|
+
|
81
|
+
=== Rack-Specific Variables
|
82
|
+
|
83
|
+
In addition to CGI variables, the Rack environment includes Rack-specific variables. These variables are prefixed with <tt>rack.</tt> and are reserved for use by the Rack specification, or by the classes that ship with Rack.
|
84
|
+
|
85
|
+
==== <tt>rack.url_scheme</tt>
|
86
|
+
|
87
|
+
The URL scheme, which must be one of <tt>http</tt>, <tt>https</tt>, <tt>ws</tt> or <tt>wss</tt>. This can never be an empty string, and so is always required. The scheme should be set according to the last hop. For example, if a client makes a request to a reverse proxy over HTTPS, but the connection between the reverse proxy and the server is over plain HTTP, the reverse proxy should set <tt>rack.url_scheme</tt> to <tt>http</tt>.
|
88
|
+
|
89
|
+
==== <tt>rack.protocol</tt>
|
90
|
+
|
91
|
+
An optional +Array+ of +String+ values, containing the protocols advertised by the client in the <tt>upgrade</tt> header (HTTP/1) or the <tt>:protocol</tt> pseudo-header (HTTP/2+).
|
92
|
+
|
93
|
+
==== <tt>rack.session</tt>
|
94
|
+
|
95
|
+
An optional +Hash+-like interface for storing request session data. The store must implement:
|
96
|
+
* <tt>store(key, value)</tt> (aliased as <tt>[]=</tt>) to set a value for a key,
|
97
|
+
* <tt>fetch(key, default = nil)</tt> (aliased as <tt>[]</tt>) to retrieve a value for a key,
|
98
|
+
* <tt>delete(key)</tt> to delete a key,
|
99
|
+
* <tt>clear</tt> to clear the session,
|
100
|
+
* <tt>to_hash</tt> (optional) to retrieve the session as a Hash.
|
101
|
+
|
102
|
+
==== <tt>rack.logger</tt>
|
103
|
+
|
104
|
+
An optional +Logger+-like interface for logging messages. The logger must implement:
|
105
|
+
* <tt>info(message, &block)</tt>,
|
106
|
+
* <tt>debug(message, &block)</tt>,
|
107
|
+
* <tt>warn(message, &block)</tt>,
|
108
|
+
* <tt>error(message, &block)</tt>,
|
109
|
+
* <tt>fatal(message, &block)</tt>.
|
110
|
+
|
111
|
+
==== <tt>rack.multipart.buffer_size</tt>
|
112
|
+
|
113
|
+
An optional +Integer+ hint to the multipart parser as to what chunk size to use for reads and writes.
|
114
|
+
|
115
|
+
==== <tt>rack.multipart.tempfile_factory</tt>
|
116
|
+
|
117
|
+
An optional object for constructing temporary files for multipart form data. The factory must implement:
|
118
|
+
* <tt>call(filename, content_type)</tt> to create a temporary file for a multipart form field.
|
119
|
+
The factory must return an +IO+-like object that responds to <tt><<</tt> and optionally <tt>rewind</tt>.
|
120
|
+
|
121
|
+
==== <tt>rack.hijack?</tt>
|
122
|
+
|
123
|
+
If present and truthy, indicates that the server supports partial hijacking. See the section below on hijacking for more information.
|
124
|
+
|
125
|
+
==== <tt>rack.hijack</tt>
|
126
|
+
|
127
|
+
If present, an object responding to +call+ that is used to perform a full hijack. See the section below on hijacking for more information.
|
128
|
+
|
129
|
+
==== <tt>rack.early_hints</tt>
|
130
|
+
|
131
|
+
If present, an object responding to +call+ that is used to send early hints. See the section below on early hints for more information.
|
132
|
+
|
133
|
+
==== <tt>rack.input</tt>
|
134
|
+
|
135
|
+
If present, the input stream. See the section below on the input stream for more information.
|
136
|
+
|
137
|
+
==== <tt>rack.errors</tt>
|
138
|
+
|
139
|
+
The error stream. See the section below on the error stream for more information.
|
140
|
+
|
141
|
+
==== <tt>rack.response_finished</tt>
|
142
|
+
|
143
|
+
If present, an array of callables that will be run by the server after the response has been processed. The callables are called with <tt>environment, status, headers, error</tt> arguments and should not raise any exceptions. The callables would typically be called after sending the response to the client, but it could also be called if an error occurs while generating the response or sending the response (in that case, the +error+ argument will be a kind of +Exception+). The callables will be called in reverse order.
|
144
|
+
|
149
145
|
=== The Input Stream
|
150
146
|
|
151
|
-
The input stream is an IO
|
152
|
-
|
153
|
-
|
154
|
-
must be
|
155
|
-
|
156
|
-
* +
|
157
|
-
|
158
|
-
* +read+
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
and +buffer+ must be a String and may not be nil.
|
163
|
-
|
164
|
-
If +length+ is given and not nil, then this method reads at most
|
165
|
-
+length+ bytes from the input stream.
|
166
|
-
|
167
|
-
If +length+ is not given or nil, then this method reads
|
168
|
-
all data until EOF.
|
169
|
-
|
170
|
-
When EOF is reached, this method returns nil if +length+ is given
|
171
|
-
and not nil, or "" if +length+ is not given or is nil.
|
172
|
-
|
173
|
-
If +buffer+ is given, then the read data will be placed
|
174
|
-
into +buffer+ instead of a newly created String object.
|
175
|
-
* +each+ must be called without arguments and only yield Strings.
|
176
|
-
* +rewind+ must be called without arguments. It rewinds the input
|
177
|
-
stream back to the beginning. It must not raise Errno::ESPIPE:
|
178
|
-
that is, it may not be a pipe or a socket. Therefore, handler
|
179
|
-
developers must buffer the input data into some rewindable object
|
180
|
-
if the underlying input stream is not rewindable.
|
181
|
-
* +close+ must never be called on the input stream.
|
147
|
+
The input stream is an +IO+-like object which contains the raw HTTP request data. When applicable, its external encoding must be <tt>ASCII-8BIT</tt> and it must be opened in binary mode. The input stream must respond to +gets+, +each+, and +read+:
|
148
|
+
* +gets+ must be called without arguments and return a +String+, or +nil+ on EOF (end-of-file).
|
149
|
+
* +read+ behaves like <tt>IO#read</tt>. Its signature is <tt>read([length, [buffer]])</tt>.
|
150
|
+
* If given, +length+ must be a non-negative Integer (>= 0) or +nil+, and +buffer+ must be a +String+ and may not be +nil+.
|
151
|
+
* If +length+ is given and not +nil+, then this method reads at most +length+ bytes from the input stream.
|
152
|
+
* If +length+ is not given or +nil+, then this method reads all data until EOF.
|
153
|
+
* When EOF is reached, this method returns +nil+ if +length+ is given and not +nil+, or +""+ if +length+ is not given or is +nil+.
|
154
|
+
* If +buffer+ is given, then the read data will be placed into +buffer+ instead of a newly created +String+.
|
155
|
+
* +each+ must be called without arguments and only yield +String+ values.
|
156
|
+
* +close+ can be called on the input stream to indicate that any remaining input is not needed.
|
157
|
+
|
182
158
|
=== The Error Stream
|
183
|
-
|
159
|
+
|
160
|
+
The error stream must respond to +puts+, +write+ and +flush+:
|
184
161
|
* +puts+ must be called with a single argument that responds to +to_s+.
|
185
|
-
* +write+ must be called with a single argument that is a String
|
186
|
-
* +flush+ must be called without arguments and must be called
|
187
|
-
in order to make the error appear for sure.
|
162
|
+
* +write+ must be called with a single argument that is a +String+.
|
163
|
+
* +flush+ must be called without arguments and must be called in order to make the error appear for sure.
|
188
164
|
* +close+ must never be called on the error stream.
|
165
|
+
|
189
166
|
=== Hijacking
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
rack.
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
rack.
|
214
|
-
|
215
|
-
|
216
|
-
If rack.
|
217
|
-
|
218
|
-
If rack.hijack? is false, then rack.hijack_io should not be set.
|
219
|
-
==== Response (after headers)
|
220
|
-
It is also possible to hijack a response after the status and headers
|
221
|
-
have been sent.
|
222
|
-
In order to do this, an application may set the special header
|
223
|
-
<tt>rack.hijack</tt> to an object that responds to <tt>call</tt>
|
224
|
-
accepting an argument that conforms to the <tt>rack.hijack_io</tt>
|
225
|
-
protocol.
|
226
|
-
|
227
|
-
After the headers have been sent, and this hijack callback has been
|
228
|
-
called, the application is now responsible for the remaining lifecycle
|
229
|
-
of the IO. The application is also responsible for maintaining HTTP
|
230
|
-
semantics. Of specific note, in almost all cases in the current SPEC,
|
231
|
-
applications will have wanted to specify the header Connection:close in
|
232
|
-
HTTP/1.1, and not Connection:keep-alive, as there is no protocol for
|
233
|
-
returning hijacked sockets to the web server. For that purpose, use the
|
234
|
-
body streaming API instead (progressively yielding strings via each).
|
235
|
-
|
236
|
-
Servers must ignore the <tt>body</tt> part of the response tuple when
|
237
|
-
the <tt>rack.hijack</tt> response API is in use.
|
238
|
-
|
239
|
-
The special response header <tt>rack.hijack</tt> must only be set
|
240
|
-
if the request env has <tt>rack.hijack?</tt> <tt>true</tt>.
|
241
|
-
==== Conventions
|
242
|
-
* Middleware should not use hijack unless it is handling the whole
|
243
|
-
response.
|
244
|
-
* Middleware may wrap the IO object for the response pattern.
|
245
|
-
* Middleware should not wrap the IO object for the request pattern. The
|
246
|
-
request pattern is intended to provide the hijacker with "raw tcp".
|
167
|
+
|
168
|
+
The hijacking interfaces provides a means for an application to take control of the HTTP connection. There are two distinct hijack interfaces: full hijacking where the application takes over the raw connection, and partial hijacking where the application takes over just the response body stream. In both cases, the application is responsible for closing the hijacked stream.
|
169
|
+
|
170
|
+
Full hijacking only works with HTTP/1. Partial hijacking is functionally equivalent to streaming bodies, and is still optionally supported for backwards compatibility with older Rack versions.
|
171
|
+
|
172
|
+
==== Full Hijack
|
173
|
+
|
174
|
+
Full hijack is used to completely take over an HTTP/1 connection. It occurs before any headers are written and causes the server to ignore any response generated by the application. It is intended to be used when applications need access to the raw HTTP/1 connection.
|
175
|
+
|
176
|
+
If <tt>rack.hijack</tt> is present in +env+, it must respond to +call+ and return an +IO+ object which can be used to read and write to the underlying connection using HTTP/1 semantics and formatting.
|
177
|
+
|
178
|
+
==== Partial Hijack
|
179
|
+
|
180
|
+
Partial hijack is used for bi-directional streaming of the request and response body. It occurs after the status and headers are written by the server and causes the server to ignore the Body of the response. It is intended to be used when applications need bi-directional streaming.
|
181
|
+
|
182
|
+
If <tt>rack.hijack?</tt> is present in +env+ and truthy, an application may set the special response header <tt>rack.hijack</tt> to an object that responds to +call+, accepting a +stream+ argument.
|
183
|
+
|
184
|
+
After the response status and headers have been sent, this hijack callback will be called with a +stream+ argument which follows the same interface as outlined in "Streaming Body". Servers must ignore the +body+ part of the response tuple when the <tt>rack.hijack</tt> response header is present. Using an empty +Array+ is recommended.
|
185
|
+
|
186
|
+
If <tt>rack.hijack?</tt> is not present and truthy, the special response header <tt>rack.hijack</tt> must not be present in the response headers.
|
187
|
+
|
188
|
+
=== Early Hints
|
189
|
+
|
190
|
+
The application or any middleware may call the <tt>rack.early_hints</tt> with an object which would be valid as the headers of a Rack response.
|
191
|
+
|
192
|
+
If <tt>rack.early_hints</tt> is present, it must respond to +call+.
|
193
|
+
If <tt>rack.early_hints</tt> is called, it must be called with valid Rack response headers.
|
194
|
+
|
247
195
|
== The Response
|
196
|
+
|
197
|
+
Outgoing HTTP responses are generated from the response tuple generated by the application. The response tuple is an +Array+ of three elements, which are: the HTTP status, the headers, and the response body. The Rack application is responsible for ensuring that the response tuple is well-formed and should follow the rules set out in this specification.
|
198
|
+
|
248
199
|
=== The Status
|
249
|
-
|
250
|
-
greater than or equal to 100.
|
200
|
+
|
201
|
+
This is an HTTP status. It must be an Integer greater than or equal to 100.
|
202
|
+
|
251
203
|
=== The Headers
|
252
|
-
|
253
|
-
The header keys must be
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
contain
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
204
|
+
|
205
|
+
The headers must be an unfrozen +Hash+. The header keys must be +String+ values. Special headers starting <tt>rack.</tt> are for communicating with the server, and must not be sent back to the client.
|
206
|
+
|
207
|
+
* The headers must not contain a <tt>"status"</tt> key.
|
208
|
+
* Header keys must conform to {RFC7230}[https://tools.ietf.org/html/rfc7230] token specification, i.e. cannot contain non-printable ASCII, <tt>DQUOTE</tt> or <tt>(),/:;<=>?@[\]{}</tt>.
|
209
|
+
* Header keys must not contain uppercase ASCII characters (A-Z).
|
210
|
+
* Header values must be either a +String+, or an +Array+ of +String+ values, such that each +String+ must not contain <tt>NUL</tt> (<tt>\0</tt>), <tt>CR</tt> (<tt>\r</tt>), or <tt>LF</tt> (<tt>\n</tt>).
|
211
|
+
|
212
|
+
==== The <tt>content-type</tt> Header
|
213
|
+
|
214
|
+
There must not be a <tt>content-type</tt> header key when the status is <tt>1xx</tt>, <tt>204</tt>, or <tt>304</tt>.
|
215
|
+
|
216
|
+
==== The <tt>content-length</tt> Header
|
217
|
+
|
218
|
+
There must not be a <tt>content-length</tt> header key when the status is <tt>1xx</tt>, <tt>204</tt>, or <tt>304</tt>.
|
219
|
+
|
220
|
+
==== The <tt>rack.protocol</tt> Header
|
221
|
+
|
222
|
+
If the <tt>rack.protocol</tt> header is present, it must be a +String+, and must be one of the values from the <tt>rack.protocol</tt> array from the environment.
|
223
|
+
|
224
|
+
Setting this value informs the server that it should perform a connection upgrade. In HTTP/1, this is done using the +upgrade+ header. In HTTP/2+, this is done by accepting the request.
|
225
|
+
|
269
226
|
=== The Body
|
270
|
-
The Body must respond to +each+
|
271
|
-
and must only yield String values.
|
272
227
|
|
273
|
-
The Body
|
274
|
-
|
228
|
+
The Body is typically an +Array+ of +String+ values, an enumerable that yields +String+ values, a +Proc+, or an +IO+-like object.
|
229
|
+
|
230
|
+
The Body must respond to +each+ or +call+. It may optionally respond to +to_path+ or +to_ary+. A Body that responds to +each+ is considered to be an Enumerable Body. A Body that responds to +call+ is considered to be a Streaming Body.
|
231
|
+
|
232
|
+
A Body that responds to both +each+ and +call+ must be treated as an Enumerable Body, not a Streaming Body. If it responds to +each+, you must call +each+ and not +call+. If the Body doesn't respond to +each+, then you can assume it responds to +call+.
|
233
|
+
|
234
|
+
The Body must either be consumed or returned. The Body is consumed by optionally calling either +each+ or +call+. Then, if the Body responds to +close+, it must be called to release any resources associated with the generation of the body. In other words, +close+ must always be called at least once; typically after the web server has sent the response to the client, but also in cases where the Rack application makes internal/virtual requests and discards the response.
|
235
|
+
|
236
|
+
After calling +close+, the Body is considered closed and should not be consumed again. If the original Body is replaced by a new Body, the new Body must also consume the original Body by calling +close+ if possible.
|
237
|
+
|
238
|
+
If the Body responds to +to_path+, it must return either +nil+ or a +String+. If a +String+ is returned, it must be a path for the local file system whose contents are identical to that produced by calling +each+; this may be used by the server as an alternative, possibly more efficient way to transport the response. The +to_path+ method does not consume the body.
|
239
|
+
|
240
|
+
==== Enumerable Body
|
275
241
|
|
276
|
-
|
277
|
-
the body is replaced by a middleware after action, the original body
|
278
|
-
must be closed first, if it responds to close.
|
242
|
+
The Enumerable Body must respond to +each+, which must only be called once, must not be called after being closed, and must only yield +String+ values.
|
279
243
|
|
280
|
-
|
281
|
-
|
282
|
-
to that produced by calling +each
|
283
|
-
|
284
|
-
|
244
|
+
Middleware must not call +each+ directly on the Body. Instead, middleware can return a new Body that calls +each+ on the original Body, yielding at least once per iteration.
|
245
|
+
|
246
|
+
If the Body responds to +to_ary+, it must return an +Array+ whose contents are identical to that produced by calling +each+. Middleware may call +to_ary+ directly on the Body and return a new Body in its place. In other words, middleware can only process the Body directly if it responds to +to_ary+. If the Body responds to both +to_ary+ and +close+, its implementation of +to_ary+ must call +close+.
|
247
|
+
|
248
|
+
==== Streaming Body
|
249
|
+
|
250
|
+
The Streaming Body must respond to +call+, which must only be called once, must not be called after being closed, and accept a +stream+ argument.
|
251
|
+
|
252
|
+
The +stream+ argument must respond to: +read+, +write+, <tt><<</tt>, +flush+, +close+, +close_read+, +close_write+, and +closed?+. The semantics of these +IO+ methods must be a best effort match to those of a normal Ruby +IO+ or +Socket+ object, using standard arguments and raising standard exceptions. Servers may simply pass on real +IO+ objects to the Streaming Body. In some cases (e.g. when using <tt>transfer-encoding</tt> or HTTP/2+), the server may need to provide a wrapper that implements the required methods, in order to provide the correct semantics.
|
285
253
|
|
286
|
-
The Body commonly is an Array of Strings, the application
|
287
|
-
instance itself, or a File-like object.
|
288
254
|
== Thanks
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
everyone involved in that effort.
|
255
|
+
|
256
|
+
We'd like to thank everyone who has contributed to the Rack project over the years. Your work has made this specification possible. That includes everyone who has contributed code, documentation, bug reports, and feedback. We'd also like to thank the authors of the various web servers, frameworks, and libraries that have implemented the Rack specification. Your work has helped to make the web a better place.
|
257
|
+
|
258
|
+
Some parts of this specification are adapted from {PEP 333 – Python Web Server Gateway Interface v1.0}[https://peps.python.org/pep-0333/]. We'd like to thank everyone involved in that effort.
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative '../../constants'
|
4
|
+
|
3
5
|
module Rack
|
4
6
|
module Auth
|
5
7
|
# Rack::Auth::AbstractHandler implements common authentication functionality.
|
@@ -21,7 +23,7 @@ module Rack
|
|
21
23
|
return [ 401,
|
22
24
|
{ CONTENT_TYPE => 'text/plain',
|
23
25
|
CONTENT_LENGTH => '0',
|
24
|
-
'
|
26
|
+
'www-authenticate' => www_authenticate.to_s },
|
25
27
|
[]
|
26
28
|
]
|
27
29
|
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# XXX: Remove when removing AbstractRequest#request
|
4
|
+
require_relative '../../request'
|
5
|
+
|
3
6
|
module Rack
|
4
7
|
module Auth
|
5
8
|
class AbstractRequest
|
@@ -9,6 +12,7 @@ module Rack
|
|
9
12
|
end
|
10
13
|
|
11
14
|
def request
|
15
|
+
warn "Rack::Auth::AbstractRequest#request is deprecated and will be removed in a future version of rack.", uplevel: 1
|
12
16
|
@request ||= Request.new(@env)
|
13
17
|
end
|
14
18
|
|
@@ -25,7 +29,7 @@ module Rack
|
|
25
29
|
end
|
26
30
|
|
27
31
|
def scheme
|
28
|
-
@scheme ||= parts.first
|
32
|
+
@scheme ||= parts.first&.downcase
|
29
33
|
end
|
30
34
|
|
31
35
|
def params
|
data/lib/rack/auth/basic.rb
CHANGED
@@ -9,8 +9,6 @@ module Rack
|
|
9
9
|
#
|
10
10
|
# Initialize with the Rack application that you want protecting,
|
11
11
|
# and a block that checks if a username and password pair are valid.
|
12
|
-
#
|
13
|
-
# See also: <tt>example/protectedlobster.rb</tt>
|
14
12
|
|
15
13
|
class Basic < AbstractHandler
|
16
14
|
|
@@ -47,7 +45,7 @@ module Rack
|
|
47
45
|
end
|
48
46
|
|
49
47
|
def credentials
|
50
|
-
@credentials ||= params.
|
48
|
+
@credentials ||= params.unpack1('m').split(':', 2)
|
51
49
|
end
|
52
50
|
|
53
51
|
def username
|