File: SPEC.html

package info (click to toggle)
librack-ruby 1.1.0-4%2Bsqueeze3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze-lts
  • size: 3,204 kB
  • ctags: 1,101
  • sloc: ruby: 8,704; makefile: 9
file content (495 lines) | stat: -rw-r--r-- 18,539 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

	<title>File: SPEC ['Rack Documentation']</title>

	<link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet" />

	<script src="./js/jquery.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="./js/thickbox-compressed.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="./js/quicksearch.js" type="text/javascript"
		charset="utf-8"></script>
	<script src="./js/darkfish.js" type="text/javascript"
		charset="utf-8"></script>
</head>

<body class="file">
	<div id="metadata">
		<div id="project-metadata">
			
			
			<div id="fileindex-section" class="section project-section">
				<h3 class="section-header">Files</h3>
				<ul>
				
					<li class="file"><a href="./KNOWN-ISSUES.html">KNOWN-ISSUES</a></li>
				
					<li class="file"><a href="./RDOX.html">RDOX</a></li>
				
					<li class="file"><a href="./README.html">README</a></li>
				
					<li class="file"><a href="./SPEC.html">SPEC</a></li>
				
				</ul>
			</div>
			

			<div id="classindex-section" class="section project-section">
				<h3 class="section-header">Class Index
					<span class="search-toggle"><img src="./images/find.png"
						height="16" width="16" alt="[+]"
						title="show/hide quicksearch" /></span></h3>
				<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
				<fieldset>
					<legend>Quicksearch</legend>
					<input type="text" name="quicksearch" value=""
						class="quicksearch-field" />
				</fieldset>
				</form>

				<ul class="link-list">
				
					<li><a href="./Rack.html">Rack</a></li>
				
					<li><a href="./Rack/Adapter.html">Rack::Adapter</a></li>
				
					<li><a href="./Rack/Adapter/Camping.html">Rack::Adapter::Camping</a></li>
				
					<li><a href="./Rack/Auth.html">Rack::Auth</a></li>
				
					<li><a href="./Rack/Auth/AbstractHandler.html">Rack::Auth::AbstractHandler</a></li>
				
					<li><a href="./Rack/Auth/AbstractRequest.html">Rack::Auth::AbstractRequest</a></li>
				
					<li><a href="./Rack/Auth/Basic.html">Rack::Auth::Basic</a></li>
				
					<li><a href="./Rack/Auth/Basic/Request.html">Rack::Auth::Basic::Request</a></li>
				
					<li><a href="./Rack/Auth/Digest.html">Rack::Auth::Digest</a></li>
				
					<li><a href="./Rack/Auth/Digest/MD5.html">Rack::Auth::Digest::MD5</a></li>
				
					<li><a href="./Rack/Auth/Digest/Nonce.html">Rack::Auth::Digest::Nonce</a></li>
				
					<li><a href="./Rack/Auth/Digest/Params.html">Rack::Auth::Digest::Params</a></li>
				
					<li><a href="./Rack/Auth/Digest/Request.html">Rack::Auth::Digest::Request</a></li>
				
					<li><a href="./Rack/Builder.html">Rack::Builder</a></li>
				
					<li><a href="./Rack/Cascade.html">Rack::Cascade</a></li>
				
					<li><a href="./Rack/Chunked.html">Rack::Chunked</a></li>
				
					<li><a href="./Rack/CommonLogger.html">Rack::CommonLogger</a></li>
				
					<li><a href="./Rack/ConditionalGet.html">Rack::ConditionalGet</a></li>
				
					<li><a href="./Rack/Config.html">Rack::Config</a></li>
				
					<li><a href="./Rack/ContentLength.html">Rack::ContentLength</a></li>
				
					<li><a href="./Rack/ContentType.html">Rack::ContentType</a></li>
				
					<li><a href="./Rack/Deflater.html">Rack::Deflater</a></li>
				
					<li><a href="./Rack/Deflater/DeflateStream.html">Rack::Deflater::DeflateStream</a></li>
				
					<li><a href="./Rack/Deflater/GzipStream.html">Rack::Deflater::GzipStream</a></li>
				
					<li><a href="./Rack/Directory.html">Rack::Directory</a></li>
				
					<li><a href="./Rack/ETag.html">Rack::ETag</a></li>
				
					<li><a href="./Rack/ForwardRequest.html">Rack::ForwardRequest</a></li>
				
					<li><a href="./Rack/Handler.html">Rack::Handler</a></li>
				
					<li><a href="./Rack/Handler/CGI.html">Rack::Handler::CGI</a></li>
				
					<li><a href="./Rack/Handler/EventedMongrel.html">Rack::Handler::EventedMongrel</a></li>
				
					<li><a href="./Rack/Handler/FastCGI.html">Rack::Handler::FastCGI</a></li>
				
					<li><a href="./Rack/Handler/LSWS.html">Rack::Handler::LSWS</a></li>
				
					<li><a href="./Rack/Handler/Mongrel.html">Rack::Handler::Mongrel</a></li>
				
					<li><a href="./Rack/Handler/SCGI.html">Rack::Handler::SCGI</a></li>
				
					<li><a href="./Rack/Handler/SwiftipliedMongrel.html">Rack::Handler::SwiftipliedMongrel</a></li>
				
					<li><a href="./Rack/Handler/Thin.html">Rack::Handler::Thin</a></li>
				
					<li><a href="./Rack/Handler/WEBrick.html">Rack::Handler::WEBrick</a></li>
				
					<li><a href="./Rack/Head.html">Rack::Head</a></li>
				
					<li><a href="./Rack/Lint.html">Rack::Lint</a></li>
				
					<li><a href="./Rack/Lobster.html">Rack::Lobster</a></li>
				
					<li><a href="./Rack/Lock.html">Rack::Lock</a></li>
				
					<li><a href="./Rack/Logger.html">Rack::Logger</a></li>
				
					<li><a href="./Rack/MethodOverride.html">Rack::MethodOverride</a></li>
				
					<li><a href="./Rack/Mime.html">Rack::Mime</a></li>
				
					<li><a href="./Rack/MockRequest.html">Rack::MockRequest</a></li>
				
					<li><a href="./Rack/MockRequest/FatalWarner.html">Rack::MockRequest::FatalWarner</a></li>
				
					<li><a href="./Rack/MockRequest/FatalWarning.html">Rack::MockRequest::FatalWarning</a></li>
				
					<li><a href="./Rack/MockResponse.html">Rack::MockResponse</a></li>
				
					<li><a href="./Rack/NullLogger.html">Rack::NullLogger</a></li>
				
					<li><a href="./Rack/Recursive.html">Rack::Recursive</a></li>
				
					<li><a href="./Rack/Reloader.html">Rack::Reloader</a></li>
				
					<li><a href="./Rack/Reloader/Stat.html">Rack::Reloader::Stat</a></li>
				
					<li><a href="./Rack/Request.html">Rack::Request</a></li>
				
					<li><a href="./Rack/Response.html">Rack::Response</a></li>
				
					<li><a href="./Rack/Response/Helpers.html">Rack::Response::Helpers</a></li>
				
					<li><a href="./Rack/RewindableInput.html">Rack::RewindableInput</a></li>
				
					<li><a href="./Rack/RewindableInput/Tempfile.html">Rack::RewindableInput::Tempfile</a></li>
				
					<li><a href="./Rack/Runtime.html">Rack::Runtime</a></li>
				
					<li><a href="./Rack/Sendfile.html">Rack::Sendfile</a></li>
				
					<li><a href="./Rack/Server.html">Rack::Server</a></li>
				
					<li><a href="./Rack/Server/Options.html">Rack::Server::Options</a></li>
				
					<li><a href="./Rack/Session.html">Rack::Session</a></li>
				
					<li><a href="./Rack/Session/Abstract.html">Rack::Session::Abstract</a></li>
				
					<li><a href="./Rack/Session/Abstract/ID.html">Rack::Session::Abstract::ID</a></li>
				
					<li><a href="./Rack/Session/Cookie.html">Rack::Session::Cookie</a></li>
				
					<li><a href="./Rack/Session/Memcache.html">Rack::Session::Memcache</a></li>
				
					<li><a href="./Rack/Session/Pool.html">Rack::Session::Pool</a></li>
				
					<li><a href="./Rack/ShowExceptions.html">Rack::ShowExceptions</a></li>
				
					<li><a href="./Rack/ShowStatus.html">Rack::ShowStatus</a></li>
				
					<li><a href="./Rack/Static.html">Rack::Static</a></li>
				
					<li><a href="./Rack/URLMap.html">Rack::URLMap</a></li>
				
					<li><a href="./Rack/Utils.html">Rack::Utils</a></li>
				
					<li><a href="./FCGI.html">FCGI</a></li>
				
					<li><a href="./FCGI/Stream.html">FCGI::Stream</a></li>
				
					<li><a href="./Multipart.html">Multipart</a></li>
				
					<li><a href="./Multipart/UploadedFile.html">Multipart::UploadedFile</a></li>
				
					<li><a href="./Context.html">Context</a></li>
				
					<li><a href="./HeaderHash.html">HeaderHash</a></li>
				
					<li><a href="./Object.html">Object</a></li>
				
				</ul>
				<div id="no-class-search-results" style="display: none;">No matching classes.</div>
			</div>

			
		</div>
	</div>

	<div id="documentation">
		<p>
This specification aims to formalize the <a href="Rack.html">Rack</a>
protocol. You can (and should) use <a href="Rack/Lint.html">Rack::Lint</a>
to enforce it. When you develop middleware, be sure to add a Lint before
and after to catch all mistakes.
</p>
<h1><a href="Rack.html">Rack</a> applications</h1>
<p>
A <a href="Rack.html">Rack</a> application is an Ruby object (not a class)
that responds to <tt>call</tt>. It takes exactly one argument, the
<b>environment</b> and returns an Array of exactly three values: The
<b>status</b>, the <b>headers</b>, and the <b>body</b>.
</p>
<h2>The Environment</h2>
<p>
The environment must be an true instance of Hash (no subclassing allowed)
that includes CGI-like headers. The application is free to modify the
environment. The environment is required to include these variables
(adopted from PEP333), except when they&#8217;d be empty, but see below.
</p>
<table>
<tr><td valign="top"><tt>REQUEST_METHOD</tt>:</td><td>The HTTP request method, such as &#8220;GET&#8221; or &#8220;POST&#8221;.
This cannot ever be an empty string, and so is always required.

</td></tr>
<tr><td valign="top"><tt>SCRIPT_NAME</tt>:</td><td>The initial portion of the request URL&#8217;s &#8220;path&#8221; that
corresponds to the application object, so that the application knows its
virtual &#8220;location&#8221;. This may be an empty string, if the
application corresponds to the &#8220;root&#8221; of the server.

</td></tr>
<tr><td valign="top"><tt>PATH_INFO</tt>:</td><td>The remainder of the request URL&#8217;s &#8220;path&#8221;, designating
the virtual &#8220;location&#8221; of the request&#8217;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 I originating from a URL.

</td></tr>
<tr><td valign="top"><tt>QUERY_STRING</tt>:</td><td>The portion of the request URL that follows the <tt>?</tt>, if any. May be
empty, but is always required!

</td></tr>
<tr><td valign="top"><tt>SERVER_NAME</tt>, <tt>SERVER_PORT</tt>:</td><td>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.

</td></tr>
<tr><td valign="top"><tt>HTTP_</tt> Variables:</td><td>Variables corresponding to the client-supplied HTTP request headers (i.e.,
variables whose names begin 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.

</td></tr>
</table>
<p>
In addition to this, the <a href="Rack.html">Rack</a> environment must
include these Rack-specific variables:
</p>
<table>
<tr><td valign="top"><tt>rack.version</tt>:</td><td>The Array [1,1], representing this version of <a href="Rack.html">Rack</a>.

</td></tr>
<tr><td valign="top"><tt>rack.url_scheme</tt>:</td><td><tt>http</tt> or <tt>https</tt>, depending on the request URL.

</td></tr>
<tr><td valign="top"><tt>rack.input</tt>:</td><td>See below, the input stream.

</td></tr>
<tr><td valign="top"><tt>rack.errors</tt>:</td><td>See below, the error stream.

</td></tr>
<tr><td valign="top"><tt>rack.multithread</tt>:</td><td>true if the application object may be simultaneously invoked by another
thread in the same process, false otherwise.

</td></tr>
<tr><td valign="top"><tt>rack.multiprocess</tt>:</td><td>true if an equivalent application object may be simultaneously invoked by
another process, false otherwise.

</td></tr>
<tr><td valign="top"><tt>rack.run_once</tt>:</td><td>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).

</td></tr>
</table>
<p>
Additional environment specifications have approved to standardized
middleware APIs. None of these are required to be implemented by the
server.
</p>
<table>
<tr><td valign="top"><tt>rack.session</tt>:</td><td>A hash like interface for storing request session data. The store must
implement: store(key, value) (aliased as []=); fetch(key, default = nil)
(aliased as []); delete(key); clear;

</td></tr>
<tr><td valign="top"><tt>rack.logger</tt>:</td><td>A common object interface for logging messages. The object must implement:

<pre>
 info(message, &amp;block)
 debug(message, &amp;block)
 warn(message, &amp;block)
 error(message, &amp;block)
 fatal(message, &amp;block)
</pre>
</td></tr>
</table>
<p>
The server or the 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 <a
href="Rack.html">Rack</a> core distribution and other accepted
specifications and must not be used otherwise. The environment must not
contain the keys <tt>HTTP_CONTENT_TYPE</tt> or <tt>HTTP_CONTENT_LENGTH</tt>
(use the versions without <tt>HTTP_</tt>). The CGI keys (named without a
period) must have String values. There are the following restrictions:
</p>
<ul>
<li><tt>rack.version</tt> must be an array of Integers.

</li>
<li><tt>rack.url_scheme</tt> must either be <tt>http</tt> or <tt>https</tt>.

</li>
<li>There must be a valid input stream in <tt>rack.input</tt>.

</li>
<li>There must be a valid error stream in <tt>rack.errors</tt>.

</li>
<li>The <tt>REQUEST_METHOD</tt> must be a valid token.

</li>
<li>The <tt>SCRIPT_NAME</tt>, if non-empty, must start with <tt>/</tt>

</li>
<li>The <tt>PATH_INFO</tt>, if non-empty, must start with <tt>/</tt>

</li>
<li>The <tt>CONTENT_LENGTH</tt>, if given, must consist of digits only.

</li>
<li>One of <tt>SCRIPT_NAME</tt> or <tt>PATH_INFO</tt> must be set.
<tt>PATH_INFO</tt> should be <tt>/</tt> if <tt>SCRIPT_NAME</tt> is empty.
<tt>SCRIPT_NAME</tt> never should be <tt>/</tt>, but instead be empty.

</li>
</ul>
<h3>The Input Stream</h3>
<p>
The input stream is an IO-like object which contains the raw HTTP POST
data. When applicable, its external encoding must be
&#8220;ASCII-8BIT&#8221; and it must be opened in binary mode, for Ruby 1.9
compatibility. The input stream must respond to <tt>gets</tt>,
<tt>each</tt>, <tt>read</tt> and <tt>rewind</tt>.
</p>
<ul>
<li><tt>gets</tt> must be called without arguments and return a string, or
<tt>nil</tt> on EOF.

</li>
<li><tt>read</tt> behaves like IO#read. Its signature is <tt>read([length,
[buffer]])</tt>. If given, <tt>length</tt> must be an non-negative Integer
(>= 0) or <tt>nil</tt>, and <tt>buffer</tt> must be a String and may not be
nil. If <tt>length</tt> is given and not nil, then this method reads at
most <tt>length</tt> bytes from the input stream. If <tt>length</tt> is not
given or nil, then this method reads all data until EOF. When EOF is
reached, this method returns nil if <tt>length</tt> is given and not nil,
or &#8220;&#8221; if <tt>length</tt> is not given or is nil. If
<tt>buffer</tt> is given, then the read data will be placed into
<tt>buffer</tt> instead of a newly created String object.

</li>
<li><tt>each</tt> must be called without arguments and only yield Strings.

</li>
<li><tt>rewind</tt> must be called without arguments. It rewinds the input
stream back to the beginning. It must not raise Errno::ESPIPE: that is, it
may not be a pipe or a socket. Therefore, handler developers must buffer
the input data into some rewindable object if the underlying input stream
is not rewindable.

</li>
<li><tt>close</tt> must never be called on the input stream.

</li>
</ul>
<h3>The Error Stream</h3>
<p>
The error stream must respond to <tt>puts</tt>, <tt>write</tt> and
<tt>flush</tt>.
</p>
<ul>
<li><tt>puts</tt> must be called with a single argument that responds to
<tt>to_s</tt>.

</li>
<li><tt>write</tt> must be called with a single argument that is a String.

</li>
<li><tt>flush</tt> must be called without arguments and must be called in order
to make the error appear for sure.

</li>
<li><tt>close</tt> must never be called on the error stream.

</li>
</ul>
<h2>The Response</h2>
<h3>The Status</h3>
<p>
This is an HTTP status. When parsed as integer (<tt>to_i</tt>), it must be
greater than or equal to 100.
</p>
<h3>The Headers</h3>
<p>
The header must respond to <tt>each</tt>, and yield values of key and
value. The header keys must be Strings. The header must not contain a
<tt>Status</tt> key, contain keys with <tt>:</tt> or newlines in their
name, contain keys names that end in <tt>-</tt> or <tt>_</tt>, but only
contain keys that consist of letters, digits, <tt>_</tt> or <tt>-</tt> and
start with a letter. The values of the header must be Strings, consisting
of lines (for multiple header values, e.g. multiple <tt>Set-Cookie</tt>
values) seperated by &#8220;n&#8220;. The lines must not contain characters
below 037.
</p>
<h3>The Content-Type</h3>
<p>
There must be a <tt>Content-Type</tt>, except when the <tt>Status</tt> is
1xx, 204 or 304, in which case there must be none given.
</p>
<h3>The Content-Length</h3>
<p>
There must not be a <tt>Content-Length</tt> header when the <tt>Status</tt>
is 1xx, 204 or 304.
</p>
<h3>The Body</h3>
<p>
The Body must respond to <tt>each</tt> and must only yield String values.
The Body itself should not be an instance of String, as this will break in
Ruby 1.9. If the Body responds to <tt>close</tt>, it will be called after
iteration. If the Body responds to <tt>to_path</tt>, it must return a
String identifying the location of a file whose contents are identical to
that produced by calling <tt>each</tt>; this may be used by the server as
an alternative, possibly more efficient way to transport the response. The
Body commonly is an Array of Strings, the application instance itself, or a
File-like object.
</p>
<h2>Thanks</h2>
<p>
Some parts of this specification are adopted from PEP333: Python Web Server
Gateway Interface v1.0 (<a
href="http://www.python.org/dev/peps/pep-0333">www.python.org/dev/peps/pep-0333</a>/).
I&#8217;d like to thank everyone involved in that effort.
</p>

	</div>

	<div id="validator-badges">
		<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
		<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
			Rdoc Generator</a> 1.1.6</small>.</p>
	</div>
</body>
</html>