serverside 0.2.6 → 0.2.7
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.
- data/CHANGELOG +22 -16
- data/Rakefile +11 -4
- data/bin/serverside +1 -1
- data/doc/rdoc/classes/Daemon.html +4 -4
- data/doc/rdoc/classes/ServerSide.html +10 -10
- data/doc/rdoc/classes/ServerSide/HTTP.html +5 -6
- data/doc/rdoc/classes/ServerSide/HTTP/Connection.html +24 -22
- data/doc/rdoc/classes/ServerSide/HTTP/Request.html +367 -121
- data/doc/rdoc/classes/ServerSide/Router.html +58 -58
- data/doc/rdoc/classes/ServerSide/StaticFiles.html +60 -49
- data/doc/rdoc/classes/ServerSide/StaticFiles/Const.html +12 -2
- data/doc/rdoc/classes/ServerSide/Template.html +12 -12
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/CHANGELOG.html +36 -31
- data/doc/rdoc/files/COPYING.html +1 -1
- data/doc/rdoc/files/README.html +1 -1
- data/doc/rdoc/files/lib/serverside/application_rb.html +1 -1
- data/doc/rdoc/files/lib/serverside/cluster_rb.html +1 -1
- data/doc/rdoc/files/lib/serverside/connection_rb.html +1 -1
- data/doc/rdoc/files/lib/serverside/core_ext_rb.html +1 -1
- data/doc/rdoc/files/lib/serverside/daemon_rb.html +1 -1
- data/doc/rdoc/files/lib/serverside/request_rb.html +8 -1
- data/doc/rdoc/files/lib/serverside/routing_rb.html +1 -1
- data/doc/rdoc/files/lib/serverside/server_rb.html +1 -1
- data/doc/rdoc/files/lib/serverside/static_rb.html +8 -1
- data/doc/rdoc/files/lib/serverside/template_rb.html +1 -1
- data/doc/rdoc/files/lib/serverside_rb.html +1 -1
- data/doc/rdoc/fr_class_index.html +0 -1
- data/doc/rdoc/fr_method_index.html +21 -20
- data/lib/serverside/connection.rb +6 -4
- data/lib/serverside/request.rb +101 -61
- data/lib/serverside/static.rb +22 -7
- data/test/functional/request_body_test.rb +93 -0
- data/test/functional/routing_server.rb +5 -5
- data/test/functional/routing_server_test.rb +3 -3
- data/test/spec/connection_spec.rb +61 -0
- data/test/spec/core_ext_spec.rb +20 -1
- data/test/unit/connection_test.rb +9 -9
- data/test/unit/request_test.rb +55 -55
- data/test/unit/server_test.rb +1 -1
- data/test/unit/static_test.rb +24 -25
- metadata +60 -60
- data/doc/rdoc/classes/ServerSide/HTTP/Const.html +0 -257
@@ -121,16 +121,16 @@ from the general to the specific.
|
|
121
121
|
<h3 class="section-bar">Methods</h3>
|
122
122
|
|
123
123
|
<div class="name-list">
|
124
|
-
<a href="#
|
125
|
-
<a href="#
|
126
|
-
<a href="#
|
127
|
-
<a href="#
|
128
|
-
<a href="#
|
129
|
-
<a href="#
|
130
|
-
<a href="#
|
131
|
-
<a href="#
|
132
|
-
<a href="#
|
133
|
-
<a href="#
|
124
|
+
<a href="#M000050">cache_constant</a>
|
125
|
+
<a href="#M000046">compile_rules</a>
|
126
|
+
<a href="#M000048">condition_part</a>
|
127
|
+
<a href="#M000053">default_handler</a>
|
128
|
+
<a href="#M000049">define_proc</a>
|
129
|
+
<a href="#M000044">has_routes?</a>
|
130
|
+
<a href="#M000045">route</a>
|
131
|
+
<a href="#M000051">route_default</a>
|
132
|
+
<a href="#M000047">rule_to_statement</a>
|
133
|
+
<a href="#M000052">unhandled</a>
|
134
134
|
</div>
|
135
135
|
</div>
|
136
136
|
|
@@ -177,11 +177,11 @@ For example, matching ’/controller/show’ against
|
|
177
177
|
<div id="methods">
|
178
178
|
<h3 class="section-bar">Public Class methods</h3>
|
179
179
|
|
180
|
-
<div id="method-
|
181
|
-
<a name="
|
180
|
+
<div id="method-M000050" class="method-detail">
|
181
|
+
<a name="M000050"></a>
|
182
182
|
|
183
183
|
<div class="method-heading">
|
184
|
-
<a href="#
|
184
|
+
<a href="#M000050" class="method-signature">
|
185
185
|
<span class="method-name">cache_constant</span><span class="method-args">(value)</span>
|
186
186
|
</a>
|
187
187
|
</div>
|
@@ -192,8 +192,8 @@ Converts a value into a local constant and freezes it. Returns the
|
|
192
192
|
constant’s tag name
|
193
193
|
</p>
|
194
194
|
<p><a class="source-toggle" href="#"
|
195
|
-
onclick="toggleCode('
|
196
|
-
<div class="method-source-code" id="
|
195
|
+
onclick="toggleCode('M000050-source');return false;">[Source]</a></p>
|
196
|
+
<div class="method-source-code" id="M000050-source">
|
197
197
|
<pre>
|
198
198
|
<span class="ruby-comment cmt"># File lib/serverside/routing.rb, line 112</span>
|
199
199
|
112: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">cache_constant</span>(<span class="ruby-identifier">value</span>)
|
@@ -206,11 +206,11 @@ constant’s tag name
|
|
206
206
|
</div>
|
207
207
|
</div>
|
208
208
|
|
209
|
-
<div id="method-
|
210
|
-
<a name="
|
209
|
+
<div id="method-M000046" class="method-detail">
|
210
|
+
<a name="M000046"></a>
|
211
211
|
|
212
212
|
<div class="method-heading">
|
213
|
-
<a href="#
|
213
|
+
<a href="#M000046" class="method-signature">
|
214
214
|
<span class="method-name">compile_rules</span><span class="method-args">()</span>
|
215
215
|
</a>
|
216
216
|
</div>
|
@@ -221,8 +221,8 @@ Compiles all rules into a respond method that is invoked when a request is
|
|
221
221
|
received.
|
222
222
|
</p>
|
223
223
|
<p><a class="source-toggle" href="#"
|
224
|
-
onclick="toggleCode('
|
225
|
-
<div class="method-source-code" id="
|
224
|
+
onclick="toggleCode('M000046-source');return false;">[Source]</a></p>
|
225
|
+
<div class="method-source-code" id="M000046-source">
|
226
226
|
<pre>
|
227
227
|
<span class="ruby-comment cmt"># File lib/serverside/routing.rb, line 47</span>
|
228
228
|
47: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">compile_rules</span>
|
@@ -236,11 +236,11 @@ received.
|
|
236
236
|
</div>
|
237
237
|
</div>
|
238
238
|
|
239
|
-
<div id="method-
|
240
|
-
<a name="
|
239
|
+
<div id="method-M000048" class="method-detail">
|
240
|
+
<a name="M000048"></a>
|
241
241
|
|
242
242
|
<div class="method-heading">
|
243
|
-
<a href="#
|
243
|
+
<a href="#M000048" class="method-signature">
|
244
244
|
<span class="method-name">condition_part</span><span class="method-args">(key, value)</span>
|
245
245
|
</a>
|
246
246
|
</div>
|
@@ -253,8 +253,8 @@ If the pattern contains parameters (for example, /controller/:action,) the
|
|
253
253
|
method creates a lambda for extracting the parameter values.
|
254
254
|
</p>
|
255
255
|
<p><a class="source-toggle" href="#"
|
256
|
-
onclick="toggleCode('
|
257
|
-
<div class="method-source-code" id="
|
256
|
+
onclick="toggleCode('M000048-source');return false;">[Source]</a></p>
|
257
|
+
<div class="method-source-code" id="M000048-source">
|
258
258
|
<pre>
|
259
259
|
<span class="ruby-comment cmt"># File lib/serverside/routing.rb, line 84</span>
|
260
260
|
84: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">condition_part</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span>)
|
@@ -280,11 +280,11 @@ method creates a lambda for extracting the parameter values.
|
|
280
280
|
</div>
|
281
281
|
</div>
|
282
282
|
|
283
|
-
<div id="method-
|
284
|
-
<a name="
|
283
|
+
<div id="method-M000049" class="method-detail">
|
284
|
+
<a name="M000049"></a>
|
285
285
|
|
286
286
|
<div class="method-heading">
|
287
|
-
<a href="#
|
287
|
+
<a href="#M000049" class="method-signature">
|
288
288
|
<span class="method-name">define_proc</span><span class="method-args">(&block)</span>
|
289
289
|
</a>
|
290
290
|
</div>
|
@@ -295,8 +295,8 @@ Converts a proc into a method, returning the method’s name (as a
|
|
295
295
|
symbol)
|
296
296
|
</p>
|
297
297
|
<p><a class="source-toggle" href="#"
|
298
|
-
onclick="toggleCode('
|
299
|
-
<div class="method-source-code" id="
|
298
|
+
onclick="toggleCode('M000049-source');return false;">[Source]</a></p>
|
299
|
+
<div class="method-source-code" id="M000049-source">
|
300
300
|
<pre>
|
301
301
|
<span class="ruby-comment cmt"># File lib/serverside/routing.rb, line 104</span>
|
302
302
|
104: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">define_proc</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
@@ -309,11 +309,11 @@ symbol)
|
|
309
309
|
</div>
|
310
310
|
</div>
|
311
311
|
|
312
|
-
<div id="method-
|
313
|
-
<a name="
|
312
|
+
<div id="method-M000044" class="method-detail">
|
313
|
+
<a name="M000044"></a>
|
314
314
|
|
315
315
|
<div class="method-heading">
|
316
|
-
<a href="#
|
316
|
+
<a href="#M000044" class="method-signature">
|
317
317
|
<span class="method-name">has_routes?</span><span class="method-args">()</span>
|
318
318
|
</a>
|
319
319
|
</div>
|
@@ -323,8 +323,8 @@ symbol)
|
|
323
323
|
Returns true if routes were defined.
|
324
324
|
</p>
|
325
325
|
<p><a class="source-toggle" href="#"
|
326
|
-
onclick="toggleCode('
|
327
|
-
<div class="method-source-code" id="
|
326
|
+
onclick="toggleCode('M000044-source');return false;">[Source]</a></p>
|
327
|
+
<div class="method-source-code" id="M000044-source">
|
328
328
|
<pre>
|
329
329
|
<span class="ruby-comment cmt"># File lib/serverside/routing.rb, line 26</span>
|
330
330
|
26: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">has_routes?</span>
|
@@ -335,11 +335,11 @@ Returns true if routes were defined.
|
|
335
335
|
</div>
|
336
336
|
</div>
|
337
337
|
|
338
|
-
<div id="method-
|
339
|
-
<a name="
|
338
|
+
<div id="method-M000045" class="method-detail">
|
339
|
+
<a name="M000045"></a>
|
340
340
|
|
341
341
|
<div class="method-heading">
|
342
|
-
<a href="#
|
342
|
+
<a href="#M000045" class="method-signature">
|
343
343
|
<span class="method-name">route</span><span class="method-args">(rule, &block)</span>
|
344
344
|
</a>
|
345
345
|
</div>
|
@@ -358,8 +358,8 @@ example:
|
|
358
358
|
ServerSide.route(lambda{path = 'mypage'}) {serve_static('mypage.html')}
|
359
359
|
</pre>
|
360
360
|
<p><a class="source-toggle" href="#"
|
361
|
-
onclick="toggleCode('
|
362
|
-
<div class="method-source-code" id="
|
361
|
+
onclick="toggleCode('M000045-source');return false;">[Source]</a></p>
|
362
|
+
<div class="method-source-code" id="M000045-source">
|
363
363
|
<pre>
|
364
364
|
<span class="ruby-comment cmt"># File lib/serverside/routing.rb, line 38</span>
|
365
365
|
38: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">route</span>(<span class="ruby-identifier">rule</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
@@ -373,11 +373,11 @@ example:
|
|
373
373
|
</div>
|
374
374
|
</div>
|
375
375
|
|
376
|
-
<div id="method-
|
377
|
-
<a name="
|
376
|
+
<div id="method-M000051" class="method-detail">
|
377
|
+
<a name="M000051"></a>
|
378
378
|
|
379
379
|
<div class="method-heading">
|
380
|
-
<a href="#
|
380
|
+
<a href="#M000051" class="method-signature">
|
381
381
|
<span class="method-name">route_default</span><span class="method-args">(&block)</span>
|
382
382
|
</a>
|
383
383
|
</div>
|
@@ -387,8 +387,8 @@ example:
|
|
387
387
|
Sets the default handler for incoming requests.
|
388
388
|
</p>
|
389
389
|
<p><a class="source-toggle" href="#"
|
390
|
-
onclick="toggleCode('
|
391
|
-
<div class="method-source-code" id="
|
390
|
+
onclick="toggleCode('M000051-source');return false;">[Source]</a></p>
|
391
|
+
<div class="method-source-code" id="M000051-source">
|
392
392
|
<pre>
|
393
393
|
<span class="ruby-comment cmt"># File lib/serverside/routing.rb, line 119</span>
|
394
394
|
119: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">route_default</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
@@ -400,11 +400,11 @@ Sets the default handler for incoming requests.
|
|
400
400
|
</div>
|
401
401
|
</div>
|
402
402
|
|
403
|
-
<div id="method-
|
404
|
-
<a name="
|
403
|
+
<div id="method-M000047" class="method-detail">
|
404
|
+
<a name="M000047"></a>
|
405
405
|
|
406
406
|
<div class="method-heading">
|
407
|
-
<a href="#
|
407
|
+
<a href="#M000047" class="method-signature">
|
408
408
|
<span class="method-name">rule_to_statement</span><span class="method-args">(rule, block)</span>
|
409
409
|
</a>
|
410
410
|
</div>
|
@@ -415,8 +415,8 @@ Converts a rule into an if statement. All keys in the rule are matched
|
|
415
415
|
against their respective values.
|
416
416
|
</p>
|
417
417
|
<p><a class="source-toggle" href="#"
|
418
|
-
onclick="toggleCode('
|
419
|
-
<div class="method-source-code" id="
|
418
|
+
onclick="toggleCode('M000047-source');return false;">[Source]</a></p>
|
419
|
+
<div class="method-source-code" id="M000047-source">
|
420
420
|
<pre>
|
421
421
|
<span class="ruby-comment cmt"># File lib/serverside/routing.rb, line 56</span>
|
422
422
|
56: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">rule_to_statement</span>(<span class="ruby-identifier">rule</span>, <span class="ruby-identifier">block</span>)
|
@@ -441,8 +441,8 @@ against their respective values.
|
|
441
441
|
|
442
442
|
<h3 class="section-bar">Public Instance methods</h3>
|
443
443
|
|
444
|
-
<div id="method-
|
445
|
-
<a name="
|
444
|
+
<div id="method-M000053" class="method-detail">
|
445
|
+
<a name="M000053"></a>
|
446
446
|
|
447
447
|
<div class="method-heading">
|
448
448
|
<span class="method-name">default_handler</span><span class="method-args">()</span>
|
@@ -450,16 +450,16 @@ against their respective values.
|
|
450
450
|
|
451
451
|
<div class="method-description">
|
452
452
|
<p>
|
453
|
-
Alias for <a href="Router.html#
|
453
|
+
Alias for <a href="Router.html#M000052">unhandled</a>
|
454
454
|
</p>
|
455
455
|
</div>
|
456
456
|
</div>
|
457
457
|
|
458
|
-
<div id="method-
|
459
|
-
<a name="
|
458
|
+
<div id="method-M000052" class="method-detail">
|
459
|
+
<a name="M000052"></a>
|
460
460
|
|
461
461
|
<div class="method-heading">
|
462
|
-
<a href="#
|
462
|
+
<a href="#M000052" class="method-signature">
|
463
463
|
<span class="method-name">unhandled</span><span class="method-args">()</span>
|
464
464
|
</a>
|
465
465
|
</div>
|
@@ -469,8 +469,8 @@ Alias for <a href="Router.html#M000051">unhandled</a>
|
|
469
469
|
Generic responder for unhandled requests.
|
470
470
|
</p>
|
471
471
|
<p><a class="source-toggle" href="#"
|
472
|
-
onclick="toggleCode('
|
473
|
-
<div class="method-source-code" id="
|
472
|
+
onclick="toggleCode('M000052-source');return false;">[Source]</a></p>
|
473
|
+
<div class="method-source-code" id="M000052-source">
|
474
474
|
<pre>
|
475
475
|
<span class="ruby-comment cmt"># File lib/serverside/routing.rb, line 125</span>
|
476
476
|
125: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">unhandled</span>
|
@@ -136,14 +136,14 @@ an HTML page.
|
|
136
136
|
onclick="toggleCode('M000023-source');return false;">[Source]</a></p>
|
137
137
|
<div class="method-source-code" id="M000023-source">
|
138
138
|
<pre>
|
139
|
-
<span class="ruby-comment cmt"># File lib/serverside/static.rb, line
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
139
|
+
<span class="ruby-comment cmt"># File lib/serverside/static.rb, line 80</span>
|
140
|
+
80: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">serve_dir</span>(<span class="ruby-identifier">dir</span>)
|
141
|
+
81: <span class="ruby-identifier">html</span> = (<span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">DirListingStart</span> <span class="ruby-operator">%</span> [<span class="ruby-ivar">@path</span>, <span class="ruby-ivar">@path</span>]) <span class="ruby-operator">+</span>
|
142
|
+
82: <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">entries</span>(<span class="ruby-identifier">dir</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">fn</span><span class="ruby-operator">|</span>
|
143
|
+
83: (<span class="ruby-identifier">fn</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'.'</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">m</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">m</span> <span class="ruby-operator"><<</span> <span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">DirListing</span> <span class="ruby-operator">%</span> [<span class="ruby-ivar">@path</span><span class="ruby-operator">/</span><span class="ruby-identifier">fn</span>, <span class="ruby-identifier">fn</span>]
|
144
|
+
84: } <span class="ruby-operator">+</span> <span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">DirListingStop</span>
|
145
|
+
85: <span class="ruby-identifier">send_response</span>(<span class="ruby-value">200</span>, <span class="ruby-value str">'text/html'</span>, <span class="ruby-identifier">html</span>)
|
146
|
+
86: <span class="ruby-keyword kw">end</span>
|
147
147
|
</pre>
|
148
148
|
</div>
|
149
149
|
</div>
|
@@ -169,27 +169,38 @@ a match, a 304 response is rendered.
|
|
169
169
|
onclick="toggleCode('M000022-source');return false;">[Source]</a></p>
|
170
170
|
<div class="method-source-code" id="M000022-source">
|
171
171
|
<pre>
|
172
|
-
<span class="ruby-comment cmt"># File lib/serverside/static.rb, line
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
172
|
+
<span class="ruby-comment cmt"># File lib/serverside/static.rb, line 47</span>
|
173
|
+
47: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">serve_file</span>(<span class="ruby-identifier">fn</span>)
|
174
|
+
48: <span class="ruby-identifier">stat</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-identifier">fn</span>)
|
175
|
+
49: <span class="ruby-identifier">etag</span> = (<span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">ETagFormat</span> <span class="ruby-operator">%</span> [<span class="ruby-identifier">stat</span>.<span class="ruby-identifier">mtime</span>.<span class="ruby-identifier">to_i</span>, <span class="ruby-identifier">stat</span>.<span class="ruby-identifier">size</span>, <span class="ruby-identifier">stat</span>.<span class="ruby-identifier">ino</span>]).<span class="ruby-identifier">freeze</span>
|
176
|
+
50: <span class="ruby-identifier">date</span> = <span class="ruby-identifier">stat</span>.<span class="ruby-identifier">mtime</span>.<span class="ruby-identifier">httpdate</span>
|
177
|
+
51:
|
178
|
+
52: <span class="ruby-identifier">etag_match</span> = <span class="ruby-ivar">@headers</span>[<span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">IfNoneMatch</span>]
|
179
|
+
53: <span class="ruby-identifier">last_date</span> = <span class="ruby-ivar">@headers</span>[<span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">IfModifiedSince</span>]
|
180
|
+
54:
|
181
|
+
55: <span class="ruby-identifier">modified</span> = (<span class="ruby-operator">!</span><span class="ruby-identifier">etag_match</span> <span class="ruby-operator">&&</span> <span class="ruby-operator">!</span><span class="ruby-identifier">last_date</span>) <span class="ruby-operator">||</span>
|
182
|
+
56: (<span class="ruby-identifier">etag_match</span> <span class="ruby-operator">&&</span> (<span class="ruby-identifier">etag</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">etag_match</span>)) <span class="ruby-operator">||</span> (<span class="ruby-identifier">last_date</span> <span class="ruby-operator">&&</span> (<span class="ruby-identifier">last_date</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">date</span>))
|
183
|
+
57:
|
184
|
+
58: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">modified</span>
|
185
|
+
59: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@@static_files</span>[<span class="ruby-identifier">fn</span>] <span class="ruby-operator">&&</span> (<span class="ruby-ivar">@@static_files</span>[<span class="ruby-identifier">fn</span>][<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">etag</span>)
|
186
|
+
60: <span class="ruby-identifier">content</span> = <span class="ruby-ivar">@@static_files</span>[<span class="ruby-identifier">fn</span>][<span class="ruby-value">1</span>]
|
187
|
+
61: <span class="ruby-keyword kw">else</span>
|
188
|
+
62: <span class="ruby-identifier">content</span> = <span class="ruby-constant">IO</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">fn</span>).<span class="ruby-identifier">freeze</span>
|
189
|
+
63: <span class="ruby-ivar">@@static_files</span>[<span class="ruby-identifier">fn</span>] = [<span class="ruby-identifier">etag</span>.<span class="ruby-identifier">freeze</span>, <span class="ruby-identifier">content</span>]
|
190
|
+
64: <span class="ruby-keyword kw">end</span>
|
191
|
+
65:
|
192
|
+
66: <span class="ruby-identifier">send_response</span>(<span class="ruby-value">200</span>, <span class="ruby-ivar">@@mime_types</span>[<span class="ruby-constant">File</span>.<span class="ruby-identifier">extname</span>(<span class="ruby-identifier">fn</span>)], <span class="ruby-identifier">content</span>, <span class="ruby-identifier">stat</span>.<span class="ruby-identifier">size</span>, {
|
193
|
+
67: <span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">ETag</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">etag</span>,
|
194
|
+
68: <span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">LastModified</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">date</span>,
|
195
|
+
69: <span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">CacheControl</span> =<span class="ruby-operator">></span> <span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">MaxAge</span>
|
196
|
+
70: })
|
197
|
+
71: <span class="ruby-keyword kw">else</span>
|
198
|
+
72: <span class="ruby-ivar">@socket</span> <span class="ruby-operator"><<</span> ((<span class="ruby-ivar">@persistent</span> <span class="ruby-operator">?</span> <span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">NotModifiedPersist</span> <span class="ruby-operator">:</span>
|
199
|
+
73: <span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">NotModifiedClose</span>) <span class="ruby-operator">%</span> [<span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>.<span class="ruby-identifier">httpdate</span>, <span class="ruby-identifier">date</span>, <span class="ruby-identifier">etag</span>, <span class="ruby-identifier">stat</span>.<span class="ruby-identifier">size</span>])
|
200
|
+
74: <span class="ruby-keyword kw">end</span>
|
201
|
+
75: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
202
|
+
76: <span class="ruby-identifier">send_response</span>(<span class="ruby-value">404</span>, <span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">TextPlain</span>, <span class="ruby-value str">'Error reading file.'</span>)
|
203
|
+
77: <span class="ruby-keyword kw">end</span>
|
193
204
|
</pre>
|
194
205
|
</div>
|
195
206
|
</div>
|
@@ -212,20 +223,20 @@ Serves static files and directory listings.
|
|
212
223
|
onclick="toggleCode('M000025-source');return false;">[Source]</a></p>
|
213
224
|
<div class="method-source-code" id="M000025-source">
|
214
225
|
<pre>
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
226
|
+
<span class="ruby-comment cmt"># File lib/serverside/static.rb, line 95</span>
|
227
|
+
95: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">serve_static</span>(<span class="ruby-identifier">path</span>)
|
228
|
+
96: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">file?</span>(<span class="ruby-identifier">path</span>)
|
229
|
+
97: <span class="ruby-identifier">serve_file</span>(<span class="ruby-identifier">path</span>)
|
230
|
+
98: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">serve_template</span>(<span class="ruby-identifier">path</span>)
|
231
|
+
99: <span class="ruby-keyword kw">return</span>
|
232
|
+
100: <span class="ruby-keyword kw">elsif</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span>(<span class="ruby-identifier">path</span>)
|
233
|
+
101: <span class="ruby-identifier">serve_dir</span>(<span class="ruby-identifier">path</span>)
|
234
|
+
102: <span class="ruby-keyword kw">else</span>
|
235
|
+
103: <span class="ruby-identifier">send_response</span>(<span class="ruby-value">404</span>, <span class="ruby-value str">'text'</span>, <span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">FileNotFound</span>)
|
236
|
+
104: <span class="ruby-keyword kw">end</span>
|
237
|
+
105: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
238
|
+
106: <span class="ruby-identifier">send_response</span>(<span class="ruby-value">500</span>, <span class="ruby-value str">'text'</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>)
|
239
|
+
107: <span class="ruby-keyword kw">end</span>
|
229
240
|
</pre>
|
230
241
|
</div>
|
231
242
|
</div>
|
@@ -245,12 +256,12 @@ Serves static files and directory listings.
|
|
245
256
|
onclick="toggleCode('M000024-source');return false;">[Source]</a></p>
|
246
257
|
<div class="method-source-code" id="M000024-source">
|
247
258
|
<pre>
|
248
|
-
<span class="ruby-comment cmt"># File lib/serverside/static.rb, line
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
259
|
+
<span class="ruby-comment cmt"># File lib/serverside/static.rb, line 88</span>
|
260
|
+
88: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">serve_template</span>(<span class="ruby-identifier">fn</span>, <span class="ruby-identifier">b</span> = <span class="ruby-keyword kw">nil</span>)
|
261
|
+
89: <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">fn</span> <span class="ruby-operator">=~</span> <span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">RHTML</span>) <span class="ruby-operator">||</span> (<span class="ruby-constant">File</span>.<span class="ruby-identifier">file?</span>(<span class="ruby-identifier">fn</span> = <span class="ruby-identifier">fn</span> <span class="ruby-operator">+</span> <span class="ruby-value str">'.rhtml'</span>))
|
262
|
+
90: <span class="ruby-identifier">send_response</span>(<span class="ruby-value">200</span>, <span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">TextHTML</span>, <span class="ruby-constant">Template</span>.<span class="ruby-identifier">render</span>(<span class="ruby-identifier">fn</span>, <span class="ruby-identifier">b</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">binding</span>))
|
263
|
+
91: <span class="ruby-keyword kw">end</span>
|
264
|
+
92: <span class="ruby-keyword kw">end</span>
|
254
265
|
</pre>
|
255
266
|
</div>
|
256
267
|
</div>
|
@@ -121,15 +121,25 @@ Frozen constants to be used by the module.
|
|
121
121
|
<td>=</td>
|
122
122
|
<td class="context-item-value">'If-None-Match'.freeze</td>
|
123
123
|
</tr>
|
124
|
+
<tr class="top-aligned-row context-row">
|
125
|
+
<td class="context-item-name">IfModifiedSince</td>
|
126
|
+
<td>=</td>
|
127
|
+
<td class="context-item-value">'If-Modified-Since'.freeze</td>
|
128
|
+
</tr>
|
129
|
+
<tr class="top-aligned-row context-row">
|
130
|
+
<td class="context-item-name">LastModified</td>
|
131
|
+
<td>=</td>
|
132
|
+
<td class="context-item-value">"Last-Modified".freeze</td>
|
133
|
+
</tr>
|
124
134
|
<tr class="top-aligned-row context-row">
|
125
135
|
<td class="context-item-name">NotModifiedClose</td>
|
126
136
|
<td>=</td>
|
127
|
-
<td class="context-item-value">"HTTP/1.1 304 Not Modified\r\nConnection: close\r\
|
137
|
+
<td class="context-item-value">"HTTP/1.1 304 Not Modified\r\nDate: %s\r\nConnection: close\r\nLast-Modified: %s\r\nETag: %s\r\nCache-Control: #{MaxAge}\r\n\r\n".freeze</td>
|
128
138
|
</tr>
|
129
139
|
<tr class="top-aligned-row context-row">
|
130
140
|
<td class="context-item-name">NotModifiedPersist</td>
|
131
141
|
<td>=</td>
|
132
|
-
<td class="context-item-value">"HTTP/1.1 304 Not Modified\r\
|
142
|
+
<td class="context-item-value">"HTTP/1.1 304 Not Modified\r\nDate: %s\r\nLast-Modified: %s\r\nETag: %s\r\nCache-Control: #{MaxAge}\r\n\r\n".freeze</td>
|
133
143
|
</tr>
|
134
144
|
<tr class="top-aligned-row context-row">
|
135
145
|
<td class="context-item-name">TextPlain</td>
|
@@ -96,8 +96,8 @@ file changes.
|
|
96
96
|
<h3 class="section-bar">Methods</h3>
|
97
97
|
|
98
98
|
<div class="name-list">
|
99
|
-
<a href="#
|
100
|
-
<a href="#
|
99
|
+
<a href="#M000043">render</a>
|
100
|
+
<a href="#M000042">set</a>
|
101
101
|
</div>
|
102
102
|
</div>
|
103
103
|
|
@@ -119,11 +119,11 @@ file changes.
|
|
119
119
|
<div id="methods">
|
120
120
|
<h3 class="section-bar">Public Class methods</h3>
|
121
121
|
|
122
|
-
<div id="method-
|
123
|
-
<a name="
|
122
|
+
<div id="method-M000043" class="method-detail">
|
123
|
+
<a name="M000043"></a>
|
124
124
|
|
125
125
|
<div class="method-heading">
|
126
|
-
<a href="#
|
126
|
+
<a href="#M000043" class="method-signature">
|
127
127
|
<span class="method-name">render</span><span class="method-args">(name, binding)</span>
|
128
128
|
</a>
|
129
129
|
</div>
|
@@ -136,8 +136,8 @@ compares it to the file stamp, and reloads the template content if
|
|
136
136
|
necessary.
|
137
137
|
</p>
|
138
138
|
<p><a class="source-toggle" href="#"
|
139
|
-
onclick="toggleCode('
|
140
|
-
<div class="method-source-code" id="
|
139
|
+
onclick="toggleCode('M000043-source');return false;">[Source]</a></p>
|
140
|
+
<div class="method-source-code" id="M000043-source">
|
141
141
|
<pre>
|
142
142
|
<span class="ruby-comment cmt"># File lib/serverside/template.rb, line 22</span>
|
143
143
|
22: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">render</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">binding</span>)
|
@@ -158,11 +158,11 @@ necessary.
|
|
158
158
|
</div>
|
159
159
|
</div>
|
160
160
|
|
161
|
-
<div id="method-
|
162
|
-
<a name="
|
161
|
+
<div id="method-M000042" class="method-detail">
|
162
|
+
<a name="M000042"></a>
|
163
163
|
|
164
164
|
<div class="method-heading">
|
165
|
-
<a href="#
|
165
|
+
<a href="#M000042" class="method-signature">
|
166
166
|
<span class="method-name">set</span><span class="method-args">(name, body, stamp = nil)</span>
|
167
167
|
</a>
|
168
168
|
</div>
|
@@ -173,8 +173,8 @@ Stores a template for later use. The stamp parameter is used only when the
|
|
173
173
|
content of a template file is stored.
|
174
174
|
</p>
|
175
175
|
<p><a class="source-toggle" href="#"
|
176
|
-
onclick="toggleCode('
|
177
|
-
<div class="method-source-code" id="
|
176
|
+
onclick="toggleCode('M000042-source');return false;">[Source]</a></p>
|
177
|
+
<div class="method-source-code" id="M000042-source">
|
178
178
|
<pre>
|
179
179
|
<span class="ruby-comment cmt"># File lib/serverside/template.rb, line 14</span>
|
180
180
|
14: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">set</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">body</span>, <span class="ruby-identifier">stamp</span> = <span class="ruby-keyword kw">nil</span>)
|