serverside 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/CHANGELOG +16 -0
  2. data/Rakefile +16 -1
  3. data/lib/serverside/caching.rb +56 -0
  4. data/lib/serverside/request.rb +8 -4
  5. data/lib/serverside/static.rb +29 -51
  6. data/test/functional/static_server.rb +7 -0
  7. data/test/spec/caching_spec.rb +101 -0
  8. data/test/spec/connection_spec.rb +0 -2
  9. data/test/unit/request_test.rb +31 -1
  10. data/test/unit/static_test.rb +21 -25
  11. metadata +30 -75
  12. data/doc/rdoc/classes/Daemon/Base.html +0 -148
  13. data/doc/rdoc/classes/Daemon/Cluster/PidFile.html +0 -230
  14. data/doc/rdoc/classes/Daemon/Cluster.html +0 -308
  15. data/doc/rdoc/classes/Daemon/PidFile.html +0 -178
  16. data/doc/rdoc/classes/Daemon.html +0 -253
  17. data/doc/rdoc/classes/Object.html +0 -151
  18. data/doc/rdoc/classes/Proc.html +0 -151
  19. data/doc/rdoc/classes/ServerSide/Application.html +0 -172
  20. data/doc/rdoc/classes/ServerSide/HTTP/Connection.html +0 -202
  21. data/doc/rdoc/classes/ServerSide/HTTP/Request.html +0 -768
  22. data/doc/rdoc/classes/ServerSide/HTTP/Server.html +0 -164
  23. data/doc/rdoc/classes/ServerSide/HTTP.html +0 -121
  24. data/doc/rdoc/classes/ServerSide/Router.html +0 -496
  25. data/doc/rdoc/classes/ServerSide/StaticFiles/Const.html +0 -204
  26. data/doc/rdoc/classes/ServerSide/StaticFiles.html +0 -282
  27. data/doc/rdoc/classes/ServerSide/Template.html +0 -200
  28. data/doc/rdoc/classes/ServerSide.html +0 -174
  29. data/doc/rdoc/classes/String.html +0 -212
  30. data/doc/rdoc/classes/Symbol.html +0 -158
  31. data/doc/rdoc/created.rid +0 -1
  32. data/doc/rdoc/files/CHANGELOG.html +0 -356
  33. data/doc/rdoc/files/COPYING.html +0 -129
  34. data/doc/rdoc/files/README.html +0 -199
  35. data/doc/rdoc/files/lib/serverside/application_rb.html +0 -109
  36. data/doc/rdoc/files/lib/serverside/cluster_rb.html +0 -101
  37. data/doc/rdoc/files/lib/serverside/connection_rb.html +0 -101
  38. data/doc/rdoc/files/lib/serverside/core_ext_rb.html +0 -107
  39. data/doc/rdoc/files/lib/serverside/daemon_rb.html +0 -108
  40. data/doc/rdoc/files/lib/serverside/request_rb.html +0 -108
  41. data/doc/rdoc/files/lib/serverside/routing_rb.html +0 -101
  42. data/doc/rdoc/files/lib/serverside/server_rb.html +0 -108
  43. data/doc/rdoc/files/lib/serverside/static_rb.html +0 -108
  44. data/doc/rdoc/files/lib/serverside/template_rb.html +0 -108
  45. data/doc/rdoc/files/lib/serverside_rb.html +0 -131
  46. data/doc/rdoc/fr_class_index.html +0 -45
  47. data/doc/rdoc/fr_file_index.html +0 -40
  48. data/doc/rdoc/fr_method_index.html +0 -79
  49. data/doc/rdoc/index.html +0 -24
  50. data/doc/rdoc/rdoc-style.css +0 -208
@@ -1,768 +0,0 @@
1
- <?xml version="1.0" encoding="iso-8859-1"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
- <head>
8
- <title>Class: ServerSide::HTTP::Request</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
- <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
12
- <script type="text/javascript">
13
- // <![CDATA[
14
-
15
- function popupCode( url ) {
16
- window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
- }
18
-
19
- function toggleCode( id ) {
20
- if ( document.getElementById )
21
- elem = document.getElementById( id );
22
- else if ( document.all )
23
- elem = eval( "document.all." + id );
24
- else
25
- return false;
26
-
27
- elemStyle = elem.style;
28
-
29
- if ( elemStyle.display != "block" ) {
30
- elemStyle.display = "block"
31
- } else {
32
- elemStyle.display = "none"
33
- }
34
-
35
- return true;
36
- }
37
-
38
- // Make codeblocks hidden by default
39
- document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
-
41
- // ]]>
42
- </script>
43
-
44
- </head>
45
- <body>
46
-
47
-
48
-
49
- <div id="classHeader">
50
- <table class="header-table">
51
- <tr class="top-aligned-row">
52
- <td><strong>Class</strong></td>
53
- <td class="class-name-in-header">ServerSide::HTTP::Request</td>
54
- </tr>
55
- <tr class="top-aligned-row">
56
- <td><strong>In:</strong></td>
57
- <td>
58
- <a href="../../../files/lib/serverside/request_rb.html">
59
- lib/serverside/request.rb
60
- </a>
61
- <br />
62
- </td>
63
- </tr>
64
-
65
- <tr class="top-aligned-row">
66
- <td><strong>Parent:</strong></td>
67
- <td>
68
- <a href="../../Object.html">
69
- Object
70
- </a>
71
- </td>
72
- </tr>
73
- </table>
74
- </div>
75
- <!-- banner header -->
76
-
77
- <div id="bodyContent">
78
-
79
-
80
-
81
- <div id="contextContent">
82
-
83
- <div id="description">
84
- <p>
85
- The <a href="Request.html">Request</a> class encapsulates <a
86
- href="../HTTP.html">HTTP</a> requests. The request class contains methods
87
- for parsing the request and rendering a response. <a
88
- href="../HTTP.html">HTTP</a> requests are created by the connection.
89
- Descendants of HTTPRequest can be created When a connection is created, it
90
- creates new requests in a loop until the connection is closed.
91
- </p>
92
-
93
- </div>
94
-
95
-
96
- </div>
97
-
98
- <div id="method-list">
99
- <h3 class="section-bar">Methods</h3>
100
-
101
- <div class="name-list">
102
- <a href="#M000039">delete_cookie</a>&nbsp;&nbsp;
103
- <a href="#M000029">new</a>&nbsp;&nbsp;
104
- <a href="#M000031">parse</a>&nbsp;&nbsp;
105
- <a href="#M000034">parse_body</a>&nbsp;&nbsp;
106
- <a href="#M000033">parse_cookies</a>&nbsp;&nbsp;
107
- <a href="#M000032">parse_parameters</a>&nbsp;&nbsp;
108
- <a href="#M000030">process</a>&nbsp;&nbsp;
109
- <a href="#M000036">redirect</a>&nbsp;&nbsp;
110
- <a href="#M000035">send_response</a>&nbsp;&nbsp;
111
- <a href="#M000038">set_cookie</a>&nbsp;&nbsp;
112
- <a href="#M000037">stream</a>&nbsp;&nbsp;
113
- </div>
114
- </div>
115
-
116
- </div>
117
-
118
-
119
- <!-- if includes -->
120
- <div id="includes">
121
- <h3 class="section-bar">Included Modules</h3>
122
-
123
- <div id="includes-list">
124
- <span class="include-name"><a href="../StaticFiles.html">StaticFiles</a></span>
125
- </div>
126
- </div>
127
-
128
- <div id="section">
129
-
130
-
131
- <div id="constants-list">
132
- <h3 class="section-bar">Constants</h3>
133
-
134
- <div class="name-list">
135
- <table summary="Constants">
136
- <tr class="top-aligned-row context-row">
137
- <td class="context-item-name">LINE_BREAK</td>
138
- <td>=</td>
139
- <td class="context-item-value">&quot;\r\n&quot;.freeze</td>
140
- </tr>
141
- <tr class="top-aligned-row context-row">
142
- <td class="context-item-name">REQUEST_REGEXP</td>
143
- <td>=</td>
144
- <td class="context-item-value">/([A-Za-z0-9]+)\s(\/[^\/\?]*(?:\/[^\/\?]+)*)\/?(?:\?(.*))?\sHTTP\/(.+)\r/.freeze</td>
145
- <td width="3em">&nbsp;</td>
146
- <td class="context-item-desc">
147
- Here&#8217;s a nice one - parses the first line of a request. The expected
148
- format is as follows: &lt;method&gt; &lt;/path&gt;[/][?&lt;query&gt;] <a
149
- href="../HTTP.html">HTTP</a>/&lt;version&gt;
150
-
151
- </td>
152
- </tr>
153
- <tr class="top-aligned-row context-row">
154
- <td class="context-item-name">HEADER_REGEXP</td>
155
- <td>=</td>
156
- <td class="context-item-value">/([^:]+):\s?(.*)\r\n/.freeze</td>
157
- <td width="3em">&nbsp;</td>
158
- <td class="context-item-desc">
159
- Regexp for parsing headers.
160
-
161
- </td>
162
- </tr>
163
- <tr class="top-aligned-row context-row">
164
- <td class="context-item-name">CONTENT_LENGTH</td>
165
- <td>=</td>
166
- <td class="context-item-value">'Content-Length'.freeze</td>
167
- </tr>
168
- <tr class="top-aligned-row context-row">
169
- <td class="context-item-name">VERSION_1_1</td>
170
- <td>=</td>
171
- <td class="context-item-value">'1.1'.freeze</td>
172
- </tr>
173
- <tr class="top-aligned-row context-row">
174
- <td class="context-item-name">CONNECTION</td>
175
- <td>=</td>
176
- <td class="context-item-value">'Connection'.freeze</td>
177
- </tr>
178
- <tr class="top-aligned-row context-row">
179
- <td class="context-item-name">CLOSE</td>
180
- <td>=</td>
181
- <td class="context-item-value">'close'.freeze</td>
182
- </tr>
183
- <tr class="top-aligned-row context-row">
184
- <td class="context-item-name">AMPERSAND</td>
185
- <td>=</td>
186
- <td class="context-item-value">'&amp;'.freeze</td>
187
- </tr>
188
- <tr class="top-aligned-row context-row">
189
- <td class="context-item-name">PARAMETER_REGEXP</td>
190
- <td>=</td>
191
- <td class="context-item-value">/(.+)=(.*)/.freeze</td>
192
- <td width="3em">&nbsp;</td>
193
- <td class="context-item-desc">
194
- Regexp for parsing URI parameters.
195
-
196
- </td>
197
- </tr>
198
- <tr class="top-aligned-row context-row">
199
- <td class="context-item-name">EQUAL_SIGN</td>
200
- <td>=</td>
201
- <td class="context-item-value">'='.freeze</td>
202
- </tr>
203
- <tr class="top-aligned-row context-row">
204
- <td class="context-item-name">STATUS_CLOSE</td>
205
- <td>=</td>
206
- <td class="context-item-value">&quot;HTTP/1.1 %d\r\nDate: %s\r\nConnection: close\r\nContent-Type: %s\r\n%s%sContent-Length: %d\r\n\r\n&quot;.freeze</td>
207
- </tr>
208
- <tr class="top-aligned-row context-row">
209
- <td class="context-item-name">STATUS_STREAM</td>
210
- <td>=</td>
211
- <td class="context-item-value">&quot;HTTP/1.1 %d\r\nDate: %s\r\nConnection: close\r\nContent-Type: %s\r\n%s%s\r\n&quot;.freeze</td>
212
- </tr>
213
- <tr class="top-aligned-row context-row">
214
- <td class="context-item-name">STATUS_PERSIST</td>
215
- <td>=</td>
216
- <td class="context-item-value">&quot;HTTP/1.1 %d\r\nDate: %s\r\nContent-Type: %s\r\n%s%sContent-Length: %d\r\n\r\n&quot;.freeze</td>
217
- </tr>
218
- <tr class="top-aligned-row context-row">
219
- <td class="context-item-name">STATUS_REDIRECT</td>
220
- <td>=</td>
221
- <td class="context-item-value">&quot;HTTP/1.1 %d\r\nDate: %s\r\nConnection: close\r\nLocation: %s\r\n\r\n&quot;.freeze</td>
222
- </tr>
223
- <tr class="top-aligned-row context-row">
224
- <td class="context-item-name">HEADER</td>
225
- <td>=</td>
226
- <td class="context-item-value">&quot;%s: %s\r\n&quot;.freeze</td>
227
- </tr>
228
- <tr class="top-aligned-row context-row">
229
- <td class="context-item-name">EMPTY_STRING</td>
230
- <td>=</td>
231
- <td class="context-item-value">''.freeze</td>
232
- </tr>
233
- <tr class="top-aligned-row context-row">
234
- <td class="context-item-name">EMPTY_HASH</td>
235
- <td>=</td>
236
- <td class="context-item-value">{}.freeze</td>
237
- </tr>
238
- <tr class="top-aligned-row context-row">
239
- <td class="context-item-name">SLASH</td>
240
- <td>=</td>
241
- <td class="context-item-value">'/'.freeze</td>
242
- </tr>
243
- <tr class="top-aligned-row context-row">
244
- <td class="context-item-name">LOCATION</td>
245
- <td>=</td>
246
- <td class="context-item-value">'Location'.freeze</td>
247
- </tr>
248
- <tr class="top-aligned-row context-row">
249
- <td class="context-item-name">COOKIE</td>
250
- <td>=</td>
251
- <td class="context-item-value">'Cookie'</td>
252
- </tr>
253
- <tr class="top-aligned-row context-row">
254
- <td class="context-item-name">SET_COOKIE</td>
255
- <td>=</td>
256
- <td class="context-item-value">&quot;Set-Cookie: %s=%s; path=/; expires=%s\r\n&quot;.freeze</td>
257
- </tr>
258
- <tr class="top-aligned-row context-row">
259
- <td class="context-item-name">COOKIE_SPLIT</td>
260
- <td>=</td>
261
- <td class="context-item-value">/[;,] */n.freeze</td>
262
- </tr>
263
- <tr class="top-aligned-row context-row">
264
- <td class="context-item-name">COOKIE_REGEXP</td>
265
- <td>=</td>
266
- <td class="context-item-value">/\s*(.+)=(.*)\s*/.freeze</td>
267
- </tr>
268
- <tr class="top-aligned-row context-row">
269
- <td class="context-item-name">COOKIE_EXPIRED_TIME</td>
270
- <td>=</td>
271
- <td class="context-item-value">Time.at(0).freeze</td>
272
- </tr>
273
- <tr class="top-aligned-row context-row">
274
- <td class="context-item-name">CONTENT_TYPE</td>
275
- <td>=</td>
276
- <td class="context-item-value">&quot;Content-Type&quot;.freeze</td>
277
- </tr>
278
- <tr class="top-aligned-row context-row">
279
- <td class="context-item-name">CONTENT_TYPE_URL_ENCODED</td>
280
- <td>=</td>
281
- <td class="context-item-value">'application/x-www-form-urlencoded'.freeze</td>
282
- </tr>
283
- <tr class="top-aligned-row context-row">
284
- <td class="context-item-name">MULTIPART_REGEXP</td>
285
- <td>=</td>
286
- <td class="context-item-value">/multipart\/form-data.*boundary=\&quot;?([^\&quot;;,]+)/n.freeze</td>
287
- </tr>
288
- <tr class="top-aligned-row context-row">
289
- <td class="context-item-name">CONTENT_DISPOSITION_REGEXP</td>
290
- <td>=</td>
291
- <td class="context-item-value">/^Content-Disposition: form-data;([^\r]*)/m.freeze</td>
292
- </tr>
293
- <tr class="top-aligned-row context-row">
294
- <td class="context-item-name">FIELD_ATTRIBUTE_REGEXP</td>
295
- <td>=</td>
296
- <td class="context-item-value">/\s*(\w+)=\&quot;([^\&quot;]*)/.freeze</td>
297
- </tr>
298
- <tr class="top-aligned-row context-row">
299
- <td class="context-item-name">CONTENT_TYPE_REGEXP</td>
300
- <td>=</td>
301
- <td class="context-item-value">/^Content-Type: ([^\r]*)/m.freeze</td>
302
- </tr>
303
- </table>
304
- </div>
305
- </div>
306
-
307
-
308
-
309
- <div id="attribute-list">
310
- <h3 class="section-bar">Attributes</h3>
311
-
312
- <div class="name-list">
313
- <table>
314
- <tr class="top-aligned-row context-row">
315
- <td class="context-item-name">body</td>
316
- <td class="context-item-value">&nbsp;[R]&nbsp;</td>
317
- <td class="context-item-desc"></td>
318
- </tr>
319
- <tr class="top-aligned-row context-row">
320
- <td class="context-item-name">content_length</td>
321
- <td class="context-item-value">&nbsp;[R]&nbsp;</td>
322
- <td class="context-item-desc"></td>
323
- </tr>
324
- <tr class="top-aligned-row context-row">
325
- <td class="context-item-name">content_type</td>
326
- <td class="context-item-value">&nbsp;[R]&nbsp;</td>
327
- <td class="context-item-desc"></td>
328
- </tr>
329
- <tr class="top-aligned-row context-row">
330
- <td class="context-item-name">cookies</td>
331
- <td class="context-item-value">&nbsp;[R]&nbsp;</td>
332
- <td class="context-item-desc"></td>
333
- </tr>
334
- <tr class="top-aligned-row context-row">
335
- <td class="context-item-name">headers</td>
336
- <td class="context-item-value">&nbsp;[R]&nbsp;</td>
337
- <td class="context-item-desc"></td>
338
- </tr>
339
- <tr class="top-aligned-row context-row">
340
- <td class="context-item-name">method</td>
341
- <td class="context-item-value">&nbsp;[R]&nbsp;</td>
342
- <td class="context-item-desc"></td>
343
- </tr>
344
- <tr class="top-aligned-row context-row">
345
- <td class="context-item-name">parameters</td>
346
- <td class="context-item-value">&nbsp;[R]&nbsp;</td>
347
- <td class="context-item-desc"></td>
348
- </tr>
349
- <tr class="top-aligned-row context-row">
350
- <td class="context-item-name">path</td>
351
- <td class="context-item-value">&nbsp;[R]&nbsp;</td>
352
- <td class="context-item-desc"></td>
353
- </tr>
354
- <tr class="top-aligned-row context-row">
355
- <td class="context-item-name">persistent</td>
356
- <td class="context-item-value">&nbsp;[R]&nbsp;</td>
357
- <td class="context-item-desc"></td>
358
- </tr>
359
- <tr class="top-aligned-row context-row">
360
- <td class="context-item-name">query</td>
361
- <td class="context-item-value">&nbsp;[R]&nbsp;</td>
362
- <td class="context-item-desc"></td>
363
- </tr>
364
- <tr class="top-aligned-row context-row">
365
- <td class="context-item-name">response_cookies</td>
366
- <td class="context-item-value">&nbsp;[R]&nbsp;</td>
367
- <td class="context-item-desc"></td>
368
- </tr>
369
- <tr class="top-aligned-row context-row">
370
- <td class="context-item-name">socket</td>
371
- <td class="context-item-value">&nbsp;[R]&nbsp;</td>
372
- <td class="context-item-desc"></td>
373
- </tr>
374
- <tr class="top-aligned-row context-row">
375
- <td class="context-item-name">version</td>
376
- <td class="context-item-value">&nbsp;[R]&nbsp;</td>
377
- <td class="context-item-desc"></td>
378
- </tr>
379
- </table>
380
- </div>
381
- </div>
382
-
383
-
384
-
385
- <!-- if method_list -->
386
- <div id="methods">
387
- <h3 class="section-bar">Public Class methods</h3>
388
-
389
- <div id="method-M000029" class="method-detail">
390
- <a name="M000029"></a>
391
-
392
- <div class="method-heading">
393
- <a href="#M000029" class="method-signature">
394
- <span class="method-name">new</span><span class="method-args">(socket)</span>
395
- </a>
396
- </div>
397
-
398
- <div class="method-description">
399
- <p>
400
- Initializes the request instance. Any descendants of <a
401
- href="Request.html">HTTP::Request</a> which override the initialize method
402
- must receive socket as the single argument, and copy it to @socket.
403
- </p>
404
- <p><a class="source-toggle" href="#"
405
- onclick="toggleCode('M000029-source');return false;">[Source]</a></p>
406
- <div class="method-source-code" id="M000029-source">
407
- <pre>
408
- <span class="ruby-comment cmt"># File lib/serverside/request.rb, line 55</span>
409
- 55: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">socket</span>)
410
- 56: <span class="ruby-ivar">@socket</span> = <span class="ruby-identifier">socket</span>
411
- 57: <span class="ruby-keyword kw">end</span>
412
- </pre>
413
- </div>
414
- </div>
415
- </div>
416
-
417
- <h3 class="section-bar">Public Instance methods</h3>
418
-
419
- <div id="method-M000039" class="method-detail">
420
- <a name="M000039"></a>
421
-
422
- <div class="method-heading">
423
- <a href="#M000039" class="method-signature">
424
- <span class="method-name">delete_cookie</span><span class="method-args">(name)</span>
425
- </a>
426
- </div>
427
-
428
- <div class="method-description">
429
- <p>
430
- Marks a cookie as deleted. The cookie is given an expires stamp in the
431
- past.
432
- </p>
433
- <p><a class="source-toggle" href="#"
434
- onclick="toggleCode('M000039-source');return false;">[Source]</a></p>
435
- <div class="method-source-code" id="M000039-source">
436
- <pre>
437
- <span class="ruby-comment cmt"># File lib/serverside/request.rb, line 185</span>
438
- 185: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete_cookie</span>(<span class="ruby-identifier">name</span>)
439
- 186: <span class="ruby-identifier">set_cookie</span>(<span class="ruby-identifier">name</span>, <span class="ruby-keyword kw">nil</span>, <span class="ruby-constant">COOKIE_EXPIRED_TIME</span>)
440
- 187: <span class="ruby-keyword kw">end</span>
441
- </pre>
442
- </div>
443
- </div>
444
- </div>
445
-
446
- <div id="method-M000031" class="method-detail">
447
- <a name="M000031"></a>
448
-
449
- <div class="method-heading">
450
- <a href="#M000031" class="method-signature">
451
- <span class="method-name">parse</span><span class="method-args">()</span>
452
- </a>
453
- </div>
454
-
455
- <div class="method-description">
456
- <p>
457
- Parses an <a href="../HTTP.html">HTTP</a> request. If the request is not
458
- valid, nil is returned. Otherwise, the <a href="../HTTP.html">HTTP</a>
459
- headers are returned. Also determines whether the connection is persistent
460
- (by checking the <a href="../HTTP.html">HTTP</a> version and the &#8216;<a
461
- href="Connection.html">Connection</a>&#8217; header).
462
- </p>
463
- <p><a class="source-toggle" href="#"
464
- onclick="toggleCode('M000031-source');return false;">[Source]</a></p>
465
- <div class="method-source-code" id="M000031-source">
466
- <pre>
467
- <span class="ruby-comment cmt"># File lib/serverside/request.rb, line 68</span>
468
- 68: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse</span>
469
- 69: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">gets</span> <span class="ruby-operator">=~</span> <span class="ruby-constant">REQUEST_REGEXP</span>
470
- 70: <span class="ruby-ivar">@method</span>, <span class="ruby-ivar">@path</span>, <span class="ruby-ivar">@query</span>, <span class="ruby-ivar">@version</span> = <span class="ruby-identifier">$1</span>.<span class="ruby-identifier">downcase</span>.<span class="ruby-identifier">to_sym</span>, <span class="ruby-identifier">$2</span>, <span class="ruby-identifier">$3</span>, <span class="ruby-identifier">$4</span>
471
- 71: <span class="ruby-ivar">@parameters</span> = <span class="ruby-ivar">@query</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">parse_parameters</span>(<span class="ruby-ivar">@query</span>) <span class="ruby-operator">:</span> {}
472
- 72: <span class="ruby-ivar">@headers</span> = {}
473
- 73: <span class="ruby-keyword kw">while</span> (<span class="ruby-identifier">line</span> = <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">gets</span>)
474
- 74: <span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">line</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> (<span class="ruby-identifier">line</span> <span class="ruby-operator">==</span> <span class="ruby-constant">LINE_BREAK</span>)
475
- 75: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">line</span> <span class="ruby-operator">=~</span> <span class="ruby-constant">HEADER_REGEXP</span>
476
- 76: <span class="ruby-ivar">@headers</span>[<span class="ruby-identifier">$1</span>.<span class="ruby-identifier">freeze</span>] = <span class="ruby-identifier">$2</span>.<span class="ruby-identifier">freeze</span>
477
- 77: <span class="ruby-keyword kw">end</span>
478
- 78: <span class="ruby-keyword kw">end</span>
479
- 79: <span class="ruby-ivar">@persistent</span> = (<span class="ruby-ivar">@version</span> <span class="ruby-operator">==</span> <span class="ruby-constant">VERSION_1_1</span>) <span class="ruby-operator">&amp;&amp;</span>
480
- 80: (<span class="ruby-ivar">@headers</span>[<span class="ruby-constant">CONNECTION</span>] <span class="ruby-operator">!=</span> <span class="ruby-constant">CLOSE</span>)
481
- 81: <span class="ruby-ivar">@cookies</span> = <span class="ruby-ivar">@headers</span>[<span class="ruby-constant">COOKIE</span>] <span class="ruby-operator">?</span> <span class="ruby-identifier">parse_cookies</span> <span class="ruby-operator">:</span> <span class="ruby-constant">EMPTY_HASH</span>
482
- 82: <span class="ruby-ivar">@response_cookies</span> = <span class="ruby-keyword kw">nil</span>
483
- 83:
484
- 84: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@content_length</span> = <span class="ruby-ivar">@headers</span>[<span class="ruby-constant">CONTENT_LENGTH</span>].<span class="ruby-identifier">to_i</span>
485
- 85: <span class="ruby-ivar">@content_type</span> = <span class="ruby-ivar">@headers</span>[<span class="ruby-constant">CONTENT_TYPE</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">CONTENT_TYPE_URL_ENCODED</span>
486
- 86: <span class="ruby-ivar">@body</span> = <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">read</span>(<span class="ruby-ivar">@content_length</span>) <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
487
- 87: <span class="ruby-identifier">parse_body</span>
488
- 88: <span class="ruby-keyword kw">end</span>
489
- 89:
490
- 90: <span class="ruby-ivar">@headers</span>
491
- 91: <span class="ruby-keyword kw">end</span>
492
- </pre>
493
- </div>
494
- </div>
495
- </div>
496
-
497
- <div id="method-M000034" class="method-detail">
498
- <a name="M000034"></a>
499
-
500
- <div class="method-heading">
501
- <a href="#M000034" class="method-signature">
502
- <span class="method-name">parse_body</span><span class="method-args">()</span>
503
- </a>
504
- </div>
505
-
506
- <div class="method-description">
507
- <p>
508
- parses the body, either by using
509
- </p>
510
- <p><a class="source-toggle" href="#"
511
- onclick="toggleCode('M000034-source');return false;">[Source]</a></p>
512
- <div class="method-source-code" id="M000034-source">
513
- <pre>
514
- <span class="ruby-comment cmt"># File lib/serverside/request.rb, line 120</span>
515
- 120: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse_body</span>
516
- 121: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@content_type</span> <span class="ruby-operator">==</span> <span class="ruby-constant">CONTENT_TYPE_URL_ENCODED</span>
517
- 122: <span class="ruby-ivar">@parameters</span>.<span class="ruby-identifier">merge!</span> <span class="ruby-identifier">parse_parameters</span>(<span class="ruby-ivar">@body</span>)
518
- 123: <span class="ruby-keyword kw">elsif</span> <span class="ruby-ivar">@content_type</span> <span class="ruby-operator">=~</span> <span class="ruby-constant">MULTIPART_REGEXP</span>
519
- 124: <span class="ruby-identifier">boundary</span> = <span class="ruby-value str">&quot;--#$1&quot;</span>
520
- 125: <span class="ruby-ivar">@body</span>.<span class="ruby-identifier">split</span>(<span class="ruby-node">/(?:\r?\n|\A)#{Regexp::quote(boundary)}(?:--)?\r\n/</span><span class="ruby-identifier">m</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">pt</span><span class="ruby-operator">|</span>
521
- 126: <span class="ruby-identifier">headers</span>, <span class="ruby-identifier">payload</span> = <span class="ruby-identifier">pt</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot;\r\n\r\n&quot;</span>, <span class="ruby-value">2</span>)
522
- 127: <span class="ruby-identifier">atts</span> = {}
523
- 128: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">headers</span> <span class="ruby-operator">=~</span> <span class="ruby-constant">CONTENT_DISPOSITION_REGEXP</span>
524
- 129: <span class="ruby-identifier">$1</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">';'</span>).<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">part</span><span class="ruby-operator">|</span>
525
- 130: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">part</span> <span class="ruby-operator">=~</span> <span class="ruby-constant">FIELD_ATTRIBUTE_REGEXP</span>
526
- 131: <span class="ruby-identifier">atts</span>[<span class="ruby-identifier">$1</span>.<span class="ruby-identifier">to_sym</span>] = <span class="ruby-identifier">$2</span>
527
- 132: <span class="ruby-keyword kw">end</span>
528
- 133: }
529
- 134: <span class="ruby-keyword kw">end</span>
530
- 135: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">headers</span> <span class="ruby-operator">=~</span> <span class="ruby-constant">CONTENT_TYPE_REGEXP</span>
531
- 136: <span class="ruby-identifier">atts</span>[<span class="ruby-identifier">:type</span>] = <span class="ruby-identifier">$1</span>
532
- 137: <span class="ruby-keyword kw">end</span>
533
- 138: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">name</span> = <span class="ruby-identifier">atts</span>[<span class="ruby-identifier">:name</span>]
534
- 139: <span class="ruby-identifier">atts</span>[<span class="ruby-identifier">:content</span>] = <span class="ruby-identifier">payload</span>
535
- 140: <span class="ruby-ivar">@parameters</span>[<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>] = <span class="ruby-identifier">atts</span>[<span class="ruby-identifier">:filename</span>] <span class="ruby-operator">?</span> <span class="ruby-identifier">atts</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">atts</span>[<span class="ruby-identifier">:content</span>]
536
- 141: <span class="ruby-keyword kw">end</span>
537
- 142: <span class="ruby-keyword kw">end</span>
538
- 143: <span class="ruby-keyword kw">end</span>
539
- 144: <span class="ruby-keyword kw">end</span>
540
- </pre>
541
- </div>
542
- </div>
543
- </div>
544
-
545
- <div id="method-M000033" class="method-detail">
546
- <a name="M000033"></a>
547
-
548
- <div class="method-heading">
549
- <a href="#M000033" class="method-signature">
550
- <span class="method-name">parse_cookies</span><span class="method-args">()</span>
551
- </a>
552
- </div>
553
-
554
- <div class="method-description">
555
- <p>
556
- Parses cookie values passed in the request
557
- </p>
558
- <p><a class="source-toggle" href="#"
559
- onclick="toggleCode('M000033-source');return false;">[Source]</a></p>
560
- <div class="method-source-code" id="M000033-source">
561
- <pre>
562
- <span class="ruby-comment cmt"># File lib/serverside/request.rb, line 105</span>
563
- 105: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse_cookies</span>
564
- 106: <span class="ruby-ivar">@headers</span>[<span class="ruby-constant">COOKIE</span>].<span class="ruby-identifier">split</span>(<span class="ruby-constant">COOKIE_SPLIT</span>).<span class="ruby-identifier">inject</span>({}) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">m</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
565
- 107: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">=~</span> <span class="ruby-constant">COOKIE_REGEXP</span>
566
- 108: <span class="ruby-identifier">m</span>[<span class="ruby-identifier">$1</span>.<span class="ruby-identifier">to_sym</span>] = <span class="ruby-identifier">$2</span>.<span class="ruby-identifier">uri_unescape</span>
567
- 109: <span class="ruby-keyword kw">end</span>
568
- 110: <span class="ruby-identifier">m</span>
569
- 111: <span class="ruby-keyword kw">end</span>
570
- 112: <span class="ruby-keyword kw">end</span>
571
- </pre>
572
- </div>
573
- </div>
574
- </div>
575
-
576
- <div id="method-M000032" class="method-detail">
577
- <a name="M000032"></a>
578
-
579
- <div class="method-heading">
580
- <a href="#M000032" class="method-signature">
581
- <span class="method-name">parse_parameters</span><span class="method-args">(query)</span>
582
- </a>
583
- </div>
584
-
585
- <div class="method-description">
586
- <p>
587
- Parses query parameters by splitting the query string and unescaping
588
- parameter values.
589
- </p>
590
- <p><a class="source-toggle" href="#"
591
- onclick="toggleCode('M000032-source');return false;">[Source]</a></p>
592
- <div class="method-source-code" id="M000032-source">
593
- <pre>
594
- <span class="ruby-comment cmt"># File lib/serverside/request.rb, line 95</span>
595
- 95: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse_parameters</span>(<span class="ruby-identifier">query</span>)
596
- 96: <span class="ruby-identifier">query</span>.<span class="ruby-identifier">split</span>(<span class="ruby-constant">AMPERSAND</span>).<span class="ruby-identifier">inject</span>({}) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">m</span>, <span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
597
- 97: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">=~</span> <span class="ruby-constant">PARAMETER_REGEXP</span>
598
- 98: <span class="ruby-identifier">m</span>[<span class="ruby-identifier">$1</span>.<span class="ruby-identifier">to_sym</span>] = <span class="ruby-identifier">$2</span>.<span class="ruby-identifier">uri_unescape</span>
599
- 99: <span class="ruby-keyword kw">end</span>
600
- 100: <span class="ruby-identifier">m</span>
601
- 101: <span class="ruby-keyword kw">end</span>
602
- 102: <span class="ruby-keyword kw">end</span>
603
- </pre>
604
- </div>
605
- </div>
606
- </div>
607
-
608
- <div id="method-M000030" class="method-detail">
609
- <a name="M000030"></a>
610
-
611
- <div class="method-heading">
612
- <a href="#M000030" class="method-signature">
613
- <span class="method-name">process</span><span class="method-args">()</span>
614
- </a>
615
- </div>
616
-
617
- <div class="method-description">
618
- <p>
619
- Processes the request by parsing it and then responding.
620
- </p>
621
- <p><a class="source-toggle" href="#"
622
- onclick="toggleCode('M000030-source');return false;">[Source]</a></p>
623
- <div class="method-source-code" id="M000030-source">
624
- <pre>
625
- <span class="ruby-comment cmt"># File lib/serverside/request.rb, line 60</span>
626
- 60: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">process</span>
627
- 61: <span class="ruby-identifier">parse</span> <span class="ruby-operator">&amp;&amp;</span> ((<span class="ruby-identifier">respond</span> <span class="ruby-operator">||</span> <span class="ruby-keyword kw">true</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-ivar">@persistent</span>)
628
- 62: <span class="ruby-keyword kw">end</span>
629
- </pre>
630
- </div>
631
- </div>
632
- </div>
633
-
634
- <div id="method-M000036" class="method-detail">
635
- <a name="M000036"></a>
636
-
637
- <div class="method-heading">
638
- <a href="#M000036" class="method-signature">
639
- <span class="method-name">redirect</span><span class="method-args">(location, permanent = false)</span>
640
- </a>
641
- </div>
642
-
643
- <div class="method-description">
644
- <p>
645
- Send a redirect response.
646
- </p>
647
- <p><a class="source-toggle" href="#"
648
- onclick="toggleCode('M000036-source');return false;">[Source]</a></p>
649
- <div class="method-source-code" id="M000036-source">
650
- <pre>
651
- <span class="ruby-comment cmt"># File lib/serverside/request.rb, line 165</span>
652
- 165: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">redirect</span>(<span class="ruby-identifier">location</span>, <span class="ruby-identifier">permanent</span> = <span class="ruby-keyword kw">false</span>)
653
- 166: <span class="ruby-ivar">@socket</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-constant">STATUS_REDIRECT</span> <span class="ruby-operator">%</span>
654
- 167: [<span class="ruby-identifier">permanent</span> <span class="ruby-value">? </span><span class="ruby-value">301</span> <span class="ruby-operator">:</span> <span class="ruby-value">302</span>, <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>.<span class="ruby-identifier">httpdate</span>, <span class="ruby-identifier">location</span>])
655
- 168: <span class="ruby-keyword kw">rescue</span>
656
- 169: <span class="ruby-keyword kw">ensure</span>
657
- 170: <span class="ruby-ivar">@persistent</span> = <span class="ruby-keyword kw">false</span>
658
- 171: <span class="ruby-keyword kw">end</span>
659
- </pre>
660
- </div>
661
- </div>
662
- </div>
663
-
664
- <div id="method-M000035" class="method-detail">
665
- <a name="M000035"></a>
666
-
667
- <div class="method-heading">
668
- <a href="#M000035" class="method-signature">
669
- <span class="method-name">send_response</span><span class="method-args">(status, content_type, body = nil, content_length = nil, headers = nil)</span>
670
- </a>
671
- </div>
672
-
673
- <div class="method-description">
674
- <p>
675
- Sends an <a href="../HTTP.html">HTTP</a> response.
676
- </p>
677
- <p><a class="source-toggle" href="#"
678
- onclick="toggleCode('M000035-source');return false;">[Source]</a></p>
679
- <div class="method-source-code" id="M000035-source">
680
- <pre>
681
- <span class="ruby-comment cmt"># File lib/serverside/request.rb, line 147</span>
682
- 147: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">send_response</span>(<span class="ruby-identifier">status</span>, <span class="ruby-identifier">content_type</span>, <span class="ruby-identifier">body</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">content_length</span> = <span class="ruby-keyword kw">nil</span>,
683
- 148: <span class="ruby-identifier">headers</span> = <span class="ruby-keyword kw">nil</span>)
684
- 149: <span class="ruby-identifier">h</span> = <span class="ruby-identifier">headers</span> <span class="ruby-value">? </span>
685
- 150: <span class="ruby-identifier">headers</span>.<span class="ruby-identifier">inject</span>(<span class="ruby-value str">''</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">m</span>, <span class="ruby-identifier">kv</span><span class="ruby-operator">|</span> <span class="ruby-identifier">m</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-constant">HEADER</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">kv</span>)} <span class="ruby-operator">:</span> <span class="ruby-value str">''</span>
686
- 151:
687
- 152: <span class="ruby-identifier">content_length</span> = <span class="ruby-identifier">body</span>.<span class="ruby-identifier">length</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">content_length</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">body</span>
688
- 153: <span class="ruby-ivar">@persistent</span> = <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">content_length</span>.<span class="ruby-identifier">nil?</span>
689
- 154:
690
- 155: <span class="ruby-comment cmt"># Select the right format to use according to circumstances.</span>
691
- 156: <span class="ruby-ivar">@socket</span> <span class="ruby-operator">&lt;&lt;</span> ((<span class="ruby-ivar">@persistent</span> <span class="ruby-operator">?</span> <span class="ruby-constant">STATUS_PERSIST</span> <span class="ruby-operator">:</span>
692
- 157: (<span class="ruby-identifier">body</span> <span class="ruby-value">? </span><span class="ruby-constant">STATUS_CLOSE</span> <span class="ruby-operator">:</span> <span class="ruby-constant">STATUS_STREAM</span>)) <span class="ruby-operator">%</span>
693
- 158: [<span class="ruby-identifier">status</span>, <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>.<span class="ruby-identifier">httpdate</span>, <span class="ruby-identifier">content_type</span>, <span class="ruby-identifier">h</span>, <span class="ruby-ivar">@response_cookies</span>, <span class="ruby-identifier">content_length</span>])
694
- 159: <span class="ruby-ivar">@socket</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">body</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">body</span>
695
- 160: <span class="ruby-keyword kw">rescue</span>
696
- 161: <span class="ruby-ivar">@persistent</span> = <span class="ruby-keyword kw">false</span>
697
- 162: <span class="ruby-keyword kw">end</span>
698
- </pre>
699
- </div>
700
- </div>
701
- </div>
702
-
703
- <div id="method-M000038" class="method-detail">
704
- <a name="M000038"></a>
705
-
706
- <div class="method-heading">
707
- <a href="#M000038" class="method-signature">
708
- <span class="method-name">set_cookie</span><span class="method-args">(name, value, expires)</span>
709
- </a>
710
- </div>
711
-
712
- <div class="method-description">
713
- <p>
714
- Sets a cookie to be included in the response.
715
- </p>
716
- <p><a class="source-toggle" href="#"
717
- onclick="toggleCode('M000038-source');return false;">[Source]</a></p>
718
- <div class="method-source-code" id="M000038-source">
719
- <pre>
720
- <span class="ruby-comment cmt"># File lib/serverside/request.rb, line 179</span>
721
- 179: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_cookie</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span>, <span class="ruby-identifier">expires</span>)
722
- 180: <span class="ruby-ivar">@response_cookies</span> <span class="ruby-operator">||=</span> <span class="ruby-value str">&quot;&quot;</span>
723
- 181: <span class="ruby-ivar">@response_cookies</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-constant">SET_COOKIE</span> <span class="ruby-operator">%</span> [<span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">uri_escape</span>, <span class="ruby-identifier">expires</span>.<span class="ruby-identifier">rfc2822</span>])
724
- 182: <span class="ruby-keyword kw">end</span>
725
- </pre>
726
- </div>
727
- </div>
728
- </div>
729
-
730
- <div id="method-M000037" class="method-detail">
731
- <a name="M000037"></a>
732
-
733
- <div class="method-heading">
734
- <a href="#M000037" class="method-signature">
735
- <span class="method-name">stream</span><span class="method-args">(body)</span>
736
- </a>
737
- </div>
738
-
739
- <div class="method-description">
740
- <p>
741
- Streams additional data to the client.
742
- </p>
743
- <p><a class="source-toggle" href="#"
744
- onclick="toggleCode('M000037-source');return false;">[Source]</a></p>
745
- <div class="method-source-code" id="M000037-source">
746
- <pre>
747
- <span class="ruby-comment cmt"># File lib/serverside/request.rb, line 174</span>
748
- 174: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stream</span>(<span class="ruby-identifier">body</span>)
749
- 175: (<span class="ruby-ivar">@socket</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">body</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">body</span>) <span class="ruby-keyword kw">rescue</span> (<span class="ruby-ivar">@persistent</span> = <span class="ruby-keyword kw">false</span>)
750
- 176: <span class="ruby-keyword kw">end</span>
751
- </pre>
752
- </div>
753
- </div>
754
- </div>
755
-
756
-
757
- </div>
758
-
759
-
760
- </div>
761
-
762
-
763
- <div id="validator-badges">
764
- <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
765
- </div>
766
-
767
- </body>
768
- </html>