serverside 0.2.0 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +26 -0
- data/README +39 -22
- data/Rakefile +18 -2
- data/bin/serverside +21 -5
- data/doc/rdoc/classes/ServerSide/Application.html +12 -19
- data/doc/rdoc/classes/ServerSide/Connection/Base.html +203 -116
- data/doc/rdoc/classes/ServerSide/Connection/Const.html +35 -5
- data/doc/rdoc/classes/ServerSide/Connection/Router.html +107 -78
- data/doc/rdoc/classes/ServerSide/Server.html +1 -1
- data/doc/rdoc/classes/ServerSide/StaticFiles/Const.html +10 -0
- data/doc/rdoc/classes/ServerSide/StaticFiles.html +73 -43
- data/doc/rdoc/classes/ServerSide/Template.html +200 -0
- data/doc/rdoc/classes/ServerSide.html +13 -8
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/CHANGELOG.html +44 -1
- data/doc/rdoc/files/README.html +63 -35
- data/doc/rdoc/files/lib/serverside/application_rb.html +1 -1
- data/doc/rdoc/files/lib/serverside/connection_rb.html +1 -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 +1 -1
- data/doc/rdoc/files/lib/serverside/template_rb.html +108 -0
- data/doc/rdoc/fr_class_index.html +1 -2
- data/doc/rdoc/fr_file_index.html +1 -0
- data/doc/rdoc/fr_method_index.html +18 -16
- data/lib/serverside/application.rb +0 -28
- data/lib/serverside/connection.rb +38 -12
- data/lib/serverside/routing.rb +23 -2
- data/lib/serverside/server.rb +1 -1
- data/lib/serverside/static.rb +12 -0
- data/lib/serverside/template.rb +36 -0
- data/test/functional/primitive_static_server_test.rb +26 -2
- data/test/functional/static_rfuzz.rb +3 -39
- data/test/spec/core_ext_spec.rb +68 -0
- data/test/unit/connection_test.rb +37 -1
- data/test/unit/template_test.rb +78 -0
- metadata +8 -6
- data/doc/rdoc/classes/ServerSide/Application/Base.html +0 -196
- data/doc/rdoc/classes/ServerSide/Application/Static.html +0 -156
- data/test/unit/application_test.rb +0 -16
@@ -99,13 +99,16 @@ create application-specific behavior.
|
|
99
99
|
<h3 class="section-bar">Methods</h3>
|
100
100
|
|
101
101
|
<div class="name-list">
|
102
|
-
<a href="#
|
103
|
-
<a href="#
|
104
|
-
<a href="#
|
105
|
-
<a href="#
|
106
|
-
<a href="#
|
107
|
-
<a href="#
|
108
|
-
<a href="#
|
102
|
+
<a href="#M000039">delete_cookie</a>
|
103
|
+
<a href="#M000030">new</a>
|
104
|
+
<a href="#M000034">parse_cookies</a>
|
105
|
+
<a href="#M000033">parse_parameters</a>
|
106
|
+
<a href="#M000032">parse_request</a>
|
107
|
+
<a href="#M000031">process</a>
|
108
|
+
<a href="#M000036">redirect</a>
|
109
|
+
<a href="#M000035">send_response</a>
|
110
|
+
<a href="#M000038">set_cookie</a>
|
111
|
+
<a href="#M000037">stream</a>
|
109
112
|
</div>
|
110
113
|
</div>
|
111
114
|
|
@@ -134,11 +137,11 @@ create application-specific behavior.
|
|
134
137
|
<div id="methods">
|
135
138
|
<h3 class="section-bar">Public Class methods</h3>
|
136
139
|
|
137
|
-
<div id="method-
|
138
|
-
<a name="
|
140
|
+
<div id="method-M000030" class="method-detail">
|
141
|
+
<a name="M000030"></a>
|
139
142
|
|
140
143
|
<div class="method-heading">
|
141
|
-
<a href="#
|
144
|
+
<a href="#M000030" class="method-signature">
|
142
145
|
<span class="method-name">new</span><span class="method-args">(conn)</span>
|
143
146
|
</a>
|
144
147
|
</div>
|
@@ -149,14 +152,14 @@ Initializes the request instance. A new thread is created for processing
|
|
149
152
|
requests.
|
150
153
|
</p>
|
151
154
|
<p><a class="source-toggle" href="#"
|
152
|
-
onclick="toggleCode('
|
153
|
-
<div class="method-source-code" id="
|
155
|
+
onclick="toggleCode('M000030-source');return false;">[Source]</a></p>
|
156
|
+
<div class="method-source-code" id="M000030-source">
|
154
157
|
<pre>
|
155
|
-
<span class="ruby-comment cmt"># File lib/serverside/connection.rb, line
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
158
|
+
<span class="ruby-comment cmt"># File lib/serverside/connection.rb, line 54</span>
|
159
|
+
54: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">conn</span>)
|
160
|
+
55: <span class="ruby-ivar">@conn</span> = <span class="ruby-identifier">conn</span>
|
161
|
+
56: <span class="ruby-ivar">@thread</span> = <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span> {<span class="ruby-identifier">process</span>}
|
162
|
+
57: <span class="ruby-keyword kw">end</span>
|
160
163
|
</pre>
|
161
164
|
</div>
|
162
165
|
</div>
|
@@ -164,11 +167,69 @@ requests.
|
|
164
167
|
|
165
168
|
<h3 class="section-bar">Public Instance methods</h3>
|
166
169
|
|
167
|
-
<div id="method-
|
168
|
-
<a name="
|
170
|
+
<div id="method-M000039" class="method-detail">
|
171
|
+
<a name="M000039"></a>
|
169
172
|
|
170
173
|
<div class="method-heading">
|
171
|
-
<a href="#
|
174
|
+
<a href="#M000039" class="method-signature">
|
175
|
+
<span class="method-name">delete_cookie</span><span class="method-args">(name)</span>
|
176
|
+
</a>
|
177
|
+
</div>
|
178
|
+
|
179
|
+
<div class="method-description">
|
180
|
+
<p>
|
181
|
+
Marks a cookie as deleted. The cookie is given an expires stamp in the
|
182
|
+
past.
|
183
|
+
</p>
|
184
|
+
<p><a class="source-toggle" href="#"
|
185
|
+
onclick="toggleCode('M000039-source');return false;">[Source]</a></p>
|
186
|
+
<div class="method-source-code" id="M000039-source">
|
187
|
+
<pre>
|
188
|
+
<span class="ruby-comment cmt"># File lib/serverside/connection.rb, line 156</span>
|
189
|
+
156: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete_cookie</span>(<span class="ruby-identifier">name</span>)
|
190
|
+
157: <span class="ruby-identifier">set_cookie</span>(<span class="ruby-identifier">name</span>, <span class="ruby-keyword kw">nil</span>, <span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">CookieExpiredTime</span>)
|
191
|
+
158: <span class="ruby-keyword kw">end</span>
|
192
|
+
</pre>
|
193
|
+
</div>
|
194
|
+
</div>
|
195
|
+
</div>
|
196
|
+
|
197
|
+
<div id="method-M000034" class="method-detail">
|
198
|
+
<a name="M000034"></a>
|
199
|
+
|
200
|
+
<div class="method-heading">
|
201
|
+
<a href="#M000034" class="method-signature">
|
202
|
+
<span class="method-name">parse_cookies</span><span class="method-args">()</span>
|
203
|
+
</a>
|
204
|
+
</div>
|
205
|
+
|
206
|
+
<div class="method-description">
|
207
|
+
<p>
|
208
|
+
Parses cookie values passed in the request
|
209
|
+
</p>
|
210
|
+
<p><a class="source-toggle" href="#"
|
211
|
+
onclick="toggleCode('M000034-source');return false;">[Source]</a></p>
|
212
|
+
<div class="method-source-code" id="M000034-source">
|
213
|
+
<pre>
|
214
|
+
<span class="ruby-comment cmt"># File lib/serverside/connection.rb, line 109</span>
|
215
|
+
109: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse_cookies</span>
|
216
|
+
110: <span class="ruby-ivar">@headers</span>[<span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">Cookie</span>].<span class="ruby-identifier">split</span>(<span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">CookieSplit</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>
|
217
|
+
111: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">=~</span> <span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">CookieRegexp</span>
|
218
|
+
112: <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>
|
219
|
+
113: <span class="ruby-keyword kw">end</span>
|
220
|
+
114: <span class="ruby-identifier">m</span>
|
221
|
+
115: <span class="ruby-keyword kw">end</span>
|
222
|
+
116: <span class="ruby-keyword kw">end</span>
|
223
|
+
</pre>
|
224
|
+
</div>
|
225
|
+
</div>
|
226
|
+
</div>
|
227
|
+
|
228
|
+
<div id="method-M000033" class="method-detail">
|
229
|
+
<a name="M000033"></a>
|
230
|
+
|
231
|
+
<div class="method-heading">
|
232
|
+
<a href="#M000033" class="method-signature">
|
172
233
|
<span class="method-name">parse_parameters</span><span class="method-args">(query)</span>
|
173
234
|
</a>
|
174
235
|
</div>
|
@@ -179,28 +240,28 @@ Parses query parameters by splitting the query string and unescaping
|
|
179
240
|
parameter values.
|
180
241
|
</p>
|
181
242
|
<p><a class="source-toggle" href="#"
|
182
|
-
onclick="toggleCode('
|
183
|
-
<div class="method-source-code" id="
|
243
|
+
onclick="toggleCode('M000033-source');return false;">[Source]</a></p>
|
244
|
+
<div class="method-source-code" id="M000033-source">
|
184
245
|
<pre>
|
185
|
-
<span class="ruby-comment cmt"># File lib/serverside/connection.rb, line
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
246
|
+
<span class="ruby-comment cmt"># File lib/serverside/connection.rb, line 99</span>
|
247
|
+
99: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse_parameters</span>(<span class="ruby-identifier">query</span>)
|
248
|
+
100: <span class="ruby-identifier">query</span>.<span class="ruby-identifier">split</span>(<span class="ruby-constant">Const</span><span class="ruby-operator">::</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>
|
249
|
+
101: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">=~</span> <span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">ParameterRegexp</span>
|
250
|
+
102: <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>
|
251
|
+
103: <span class="ruby-keyword kw">end</span>
|
252
|
+
104: <span class="ruby-identifier">m</span>
|
253
|
+
105: <span class="ruby-keyword kw">end</span>
|
254
|
+
106: <span class="ruby-keyword kw">end</span>
|
194
255
|
</pre>
|
195
256
|
</div>
|
196
257
|
</div>
|
197
258
|
</div>
|
198
259
|
|
199
|
-
<div id="method-
|
200
|
-
<a name="
|
260
|
+
<div id="method-M000032" class="method-detail">
|
261
|
+
<a name="M000032"></a>
|
201
262
|
|
202
263
|
<div class="method-heading">
|
203
|
-
<a href="#
|
264
|
+
<a href="#M000032" class="method-signature">
|
204
265
|
<span class="method-name">parse_request</span><span class="method-args">()</span>
|
205
266
|
</a>
|
206
267
|
</div>
|
@@ -213,35 +274,38 @@ connection is persistent (by checking the HTTP version and the ‘<a
|
|
213
274
|
href="../Connection.html">Connection</a>’ header).
|
214
275
|
</p>
|
215
276
|
<p><a class="source-toggle" href="#"
|
216
|
-
onclick="toggleCode('
|
217
|
-
<div class="method-source-code" id="
|
277
|
+
onclick="toggleCode('M000032-source');return false;">[Source]</a></p>
|
278
|
+
<div class="method-source-code" id="M000032-source">
|
218
279
|
<pre>
|
219
|
-
<span class="ruby-comment cmt"># File lib/serverside/connection.rb, line
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
280
|
+
<span class="ruby-comment cmt"># File lib/serverside/connection.rb, line 78</span>
|
281
|
+
78: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse_request</span>
|
282
|
+
79: <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">@conn</span>.<span class="ruby-identifier">gets</span> <span class="ruby-operator">=~</span> <span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">RequestRegexp</span>
|
283
|
+
80: <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>
|
284
|
+
81: <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> {}
|
285
|
+
82: <span class="ruby-ivar">@headers</span> = {}
|
286
|
+
83: <span class="ruby-keyword kw">while</span> (<span class="ruby-identifier">line</span> = <span class="ruby-ivar">@conn</span>.<span class="ruby-identifier">gets</span>)
|
287
|
+
84: <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">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">LineBreak</span>)
|
288
|
+
85: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">line</span> <span class="ruby-operator">=~</span> <span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">HeaderRegexp</span>
|
289
|
+
86: <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>
|
290
|
+
87: <span class="ruby-keyword kw">end</span>
|
291
|
+
88: <span class="ruby-keyword kw">end</span>
|
292
|
+
89: <span class="ruby-ivar">@persistent</span> = (<span class="ruby-ivar">@version</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">Version_1_1</span>) <span class="ruby-operator">&&</span>
|
293
|
+
90: (<span class="ruby-ivar">@headers</span>[<span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">Connection</span>] <span class="ruby-operator">!=</span> <span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">Close</span>)
|
294
|
+
91: <span class="ruby-ivar">@cookies</span> = <span class="ruby-ivar">@headers</span>[<span class="ruby-constant">Const</span><span class="ruby-operator">::</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">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">EmptyHash</span>
|
295
|
+
92: <span class="ruby-ivar">@response_cookies</span> = <span class="ruby-keyword kw">nil</span>
|
296
|
+
93:
|
297
|
+
94: <span class="ruby-ivar">@headers</span>
|
298
|
+
95: <span class="ruby-keyword kw">end</span>
|
235
299
|
</pre>
|
236
300
|
</div>
|
237
301
|
</div>
|
238
302
|
</div>
|
239
303
|
|
240
|
-
<div id="method-
|
241
|
-
<a name="
|
304
|
+
<div id="method-M000031" class="method-detail">
|
305
|
+
<a name="M000031"></a>
|
242
306
|
|
243
307
|
<div class="method-heading">
|
244
|
-
<a href="#
|
308
|
+
<a href="#M000031" class="method-signature">
|
245
309
|
<span class="method-name">process</span><span class="method-args">()</span>
|
246
310
|
</a>
|
247
311
|
</div>
|
@@ -253,35 +317,31 @@ error occurs, or the connection is not persistent, the connection is
|
|
253
317
|
closed.
|
254
318
|
</p>
|
255
319
|
<p><a class="source-toggle" href="#"
|
256
|
-
onclick="toggleCode('
|
257
|
-
<div class="method-source-code" id="
|
320
|
+
onclick="toggleCode('M000031-source');return false;">[Source]</a></p>
|
321
|
+
<div class="method-source-code" id="M000031-source">
|
258
322
|
<pre>
|
259
|
-
<span class="ruby-comment cmt"># File lib/serverside/connection.rb, line
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
67: <span class="ruby-comment cmt"># We don't care. Just close the connection.</span>
|
272
|
-
68: <span class="ruby-keyword kw">ensure</span>
|
273
|
-
69: <span class="ruby-ivar">@conn</span>.<span class="ruby-identifier">close</span>
|
274
|
-
70: <span class="ruby-keyword kw">end</span>
|
323
|
+
<span class="ruby-comment cmt"># File lib/serverside/connection.rb, line 62</span>
|
324
|
+
62: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">process</span>
|
325
|
+
63: <span class="ruby-keyword kw">while</span> <span class="ruby-keyword kw">true</span>
|
326
|
+
64: <span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">parse_request</span>
|
327
|
+
65: <span class="ruby-identifier">respond</span>
|
328
|
+
66: <span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@persistent</span>
|
329
|
+
67: <span class="ruby-keyword kw">end</span>
|
330
|
+
68: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
331
|
+
69: <span class="ruby-comment cmt"># We don't care. Just close the connection.</span>
|
332
|
+
70: <span class="ruby-keyword kw">ensure</span>
|
333
|
+
71: <span class="ruby-ivar">@conn</span>.<span class="ruby-identifier">close</span>
|
334
|
+
72: <span class="ruby-keyword kw">end</span>
|
275
335
|
</pre>
|
276
336
|
</div>
|
277
337
|
</div>
|
278
338
|
</div>
|
279
339
|
|
280
|
-
<div id="method-
|
281
|
-
<a name="
|
340
|
+
<div id="method-M000036" class="method-detail">
|
341
|
+
<a name="M000036"></a>
|
282
342
|
|
283
343
|
<div class="method-heading">
|
284
|
-
<a href="#
|
344
|
+
<a href="#M000036" class="method-signature">
|
285
345
|
<span class="method-name">redirect</span><span class="method-args">(location, permanent = false)</span>
|
286
346
|
</a>
|
287
347
|
</div>
|
@@ -291,26 +351,26 @@ closed.
|
|
291
351
|
Send a redirect response.
|
292
352
|
</p>
|
293
353
|
<p><a class="source-toggle" href="#"
|
294
|
-
onclick="toggleCode('
|
295
|
-
<div class="method-source-code" id="
|
354
|
+
onclick="toggleCode('M000036-source');return false;">[Source]</a></p>
|
355
|
+
<div class="method-source-code" id="M000036-source">
|
296
356
|
<pre>
|
297
|
-
<span class="ruby-comment cmt"># File lib/serverside/connection.rb, line
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
357
|
+
<span class="ruby-comment cmt"># File lib/serverside/connection.rb, line 137</span>
|
358
|
+
137: <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>)
|
359
|
+
138: <span class="ruby-ivar">@conn</span> <span class="ruby-operator"><<</span> (<span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">StatusRedirect</span> <span class="ruby-operator">%</span> [<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-identifier">location</span>])
|
360
|
+
139: <span class="ruby-keyword kw">rescue</span>
|
361
|
+
140: <span class="ruby-keyword kw">ensure</span>
|
362
|
+
141: <span class="ruby-ivar">@persistent</span> = <span class="ruby-keyword kw">false</span>
|
363
|
+
142: <span class="ruby-keyword kw">end</span>
|
304
364
|
</pre>
|
305
365
|
</div>
|
306
366
|
</div>
|
307
367
|
</div>
|
308
368
|
|
309
|
-
<div id="method-
|
310
|
-
<a name="
|
369
|
+
<div id="method-M000035" class="method-detail">
|
370
|
+
<a name="M000035"></a>
|
311
371
|
|
312
372
|
<div class="method-heading">
|
313
|
-
<a href="#
|
373
|
+
<a href="#M000035" class="method-signature">
|
314
374
|
<span class="method-name">send_response</span><span class="method-args">(status, content_type, body = nil, content_length = nil, headers = nil)</span>
|
315
375
|
</a>
|
316
376
|
</div>
|
@@ -320,36 +380,63 @@ Send a redirect response.
|
|
320
380
|
Sends an HTTP response.
|
321
381
|
</p>
|
322
382
|
<p><a class="source-toggle" href="#"
|
323
|
-
onclick="toggleCode('
|
324
|
-
<div class="method-source-code" id="
|
383
|
+
onclick="toggleCode('M000035-source');return false;">[Source]</a></p>
|
384
|
+
<div class="method-source-code" id="M000035-source">
|
325
385
|
<pre>
|
326
|
-
<span class="ruby-comment cmt"># File lib/serverside/connection.rb, line
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
386
|
+
<span class="ruby-comment cmt"># File lib/serverside/connection.rb, line 119</span>
|
387
|
+
119: <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>,
|
388
|
+
120: <span class="ruby-identifier">headers</span> = <span class="ruby-keyword kw">nil</span>)
|
389
|
+
121: <span class="ruby-identifier">h</span> = <span class="ruby-identifier">headers</span> <span class="ruby-value">? </span>
|
390
|
+
122: <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"><<</span> (<span class="ruby-constant">Const</span><span class="ruby-operator">::</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>
|
391
|
+
123:
|
392
|
+
124: <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">&&</span> <span class="ruby-identifier">body</span>
|
393
|
+
125: <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>
|
394
|
+
126:
|
395
|
+
127: <span class="ruby-comment cmt"># Select the right format to use according to circumstances.</span>
|
396
|
+
128: <span class="ruby-ivar">@conn</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">StatusPersist</span> <span class="ruby-operator">:</span>
|
397
|
+
129: (<span class="ruby-identifier">body</span> <span class="ruby-value">? </span><span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">StatusClose</span> <span class="ruby-operator">:</span> <span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">StatusStream</span>)) <span class="ruby-operator">%</span>
|
398
|
+
130: [<span class="ruby-identifier">status</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>])
|
399
|
+
131: <span class="ruby-ivar">@conn</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">body</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">body</span>
|
400
|
+
132: <span class="ruby-keyword kw">rescue</span>
|
401
|
+
133: <span class="ruby-ivar">@persistent</span> = <span class="ruby-keyword kw">false</span>
|
402
|
+
134: <span class="ruby-keyword kw">end</span>
|
343
403
|
</pre>
|
344
404
|
</div>
|
345
405
|
</div>
|
346
406
|
</div>
|
347
407
|
|
348
|
-
<div id="method-
|
349
|
-
<a name="
|
408
|
+
<div id="method-M000038" class="method-detail">
|
409
|
+
<a name="M000038"></a>
|
350
410
|
|
351
411
|
<div class="method-heading">
|
352
|
-
<a href="#
|
412
|
+
<a href="#M000038" class="method-signature">
|
413
|
+
<span class="method-name">set_cookie</span><span class="method-args">(name, value, expires)</span>
|
414
|
+
</a>
|
415
|
+
</div>
|
416
|
+
|
417
|
+
<div class="method-description">
|
418
|
+
<p>
|
419
|
+
Sets a cookie to be included in the response.
|
420
|
+
</p>
|
421
|
+
<p><a class="source-toggle" href="#"
|
422
|
+
onclick="toggleCode('M000038-source');return false;">[Source]</a></p>
|
423
|
+
<div class="method-source-code" id="M000038-source">
|
424
|
+
<pre>
|
425
|
+
<span class="ruby-comment cmt"># File lib/serverside/connection.rb, line 150</span>
|
426
|
+
150: <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>)
|
427
|
+
151: <span class="ruby-ivar">@response_cookies</span> <span class="ruby-operator">||=</span> <span class="ruby-value str">""</span>
|
428
|
+
152: <span class="ruby-ivar">@response_cookies</span> <span class="ruby-operator"><<</span> (<span class="ruby-constant">Const</span><span class="ruby-operator">::</span><span class="ruby-constant">SetCookie</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>])
|
429
|
+
153: <span class="ruby-keyword kw">end</span>
|
430
|
+
</pre>
|
431
|
+
</div>
|
432
|
+
</div>
|
433
|
+
</div>
|
434
|
+
|
435
|
+
<div id="method-M000037" class="method-detail">
|
436
|
+
<a name="M000037"></a>
|
437
|
+
|
438
|
+
<div class="method-heading">
|
439
|
+
<a href="#M000037" class="method-signature">
|
353
440
|
<span class="method-name">stream</span><span class="method-args">(body)</span>
|
354
441
|
</a>
|
355
442
|
</div>
|
@@ -359,13 +446,13 @@ Sends an HTTP response.
|
|
359
446
|
Streams additional data to the client.
|
360
447
|
</p>
|
361
448
|
<p><a class="source-toggle" href="#"
|
362
|
-
onclick="toggleCode('
|
363
|
-
<div class="method-source-code" id="
|
449
|
+
onclick="toggleCode('M000037-source');return false;">[Source]</a></p>
|
450
|
+
<div class="method-source-code" id="M000037-source">
|
364
451
|
<pre>
|
365
|
-
<span class="ruby-comment cmt"># File lib/serverside/connection.rb, line
|
366
|
-
|
367
|
-
|
368
|
-
|
452
|
+
<span class="ruby-comment cmt"># File lib/serverside/connection.rb, line 145</span>
|
453
|
+
145: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stream</span>(<span class="ruby-identifier">body</span>)
|
454
|
+
146: (<span class="ruby-ivar">@conn</span> <span class="ruby-operator"><<</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>)
|
455
|
+
147: <span class="ruby-keyword kw">end</span>
|
369
456
|
</pre>
|
370
457
|
</div>
|
371
458
|
</div>
|
@@ -167,17 +167,17 @@ Regexp for parsing URI parameters.
|
|
167
167
|
<tr class="top-aligned-row context-row">
|
168
168
|
<td class="context-item-name">StatusClose</td>
|
169
169
|
<td>=</td>
|
170
|
-
<td class="context-item-value">"HTTP/1.1 %d\r\nConnection: close\r\nContent-Type: %s\r\n%sContent-Length: %d\r\n\r\n".freeze</td>
|
170
|
+
<td class="context-item-value">"HTTP/1.1 %d\r\nConnection: close\r\nContent-Type: %s\r\n%s%sContent-Length: %d\r\n\r\n".freeze</td>
|
171
171
|
</tr>
|
172
172
|
<tr class="top-aligned-row context-row">
|
173
173
|
<td class="context-item-name">StatusStream</td>
|
174
174
|
<td>=</td>
|
175
|
-
<td class="context-item-value">"HTTP/1.1 %d\r\nConnection: close\r\nContent-Type: %s\r\n%s\r\n".freeze</td>
|
175
|
+
<td class="context-item-value">"HTTP/1.1 %d\r\nConnection: close\r\nContent-Type: %s\r\n%s%s\r\n".freeze</td>
|
176
176
|
</tr>
|
177
177
|
<tr class="top-aligned-row context-row">
|
178
178
|
<td class="context-item-name">StatusPersist</td>
|
179
179
|
<td>=</td>
|
180
|
-
<td class="context-item-value">"HTTP/1.1 %d\r\nContent-Type: %s\r\n%sContent-Length: %d\r\n\r\n".freeze</td>
|
180
|
+
<td class="context-item-value">"HTTP/1.1 %d\r\nContent-Type: %s\r\n%s%sContent-Length: %d\r\n\r\n".freeze</td>
|
181
181
|
</tr>
|
182
182
|
<tr class="top-aligned-row context-row">
|
183
183
|
<td class="context-item-name">StatusRedirect</td>
|
@@ -190,10 +190,15 @@ Regexp for parsing URI parameters.
|
|
190
190
|
<td class="context-item-value">"%s: %s\r\n".freeze</td>
|
191
191
|
</tr>
|
192
192
|
<tr class="top-aligned-row context-row">
|
193
|
-
<td class="context-item-name">
|
193
|
+
<td class="context-item-name">EmptyString</td>
|
194
194
|
<td>=</td>
|
195
195
|
<td class="context-item-value">''.freeze</td>
|
196
196
|
</tr>
|
197
|
+
<tr class="top-aligned-row context-row">
|
198
|
+
<td class="context-item-name">EmptyHash</td>
|
199
|
+
<td>=</td>
|
200
|
+
<td class="context-item-value">{}.freeze</td>
|
201
|
+
</tr>
|
197
202
|
<tr class="top-aligned-row context-row">
|
198
203
|
<td class="context-item-name">Slash</td>
|
199
204
|
<td>=</td>
|
@@ -202,7 +207,32 @@ Regexp for parsing URI parameters.
|
|
202
207
|
<tr class="top-aligned-row context-row">
|
203
208
|
<td class="context-item-name">Location</td>
|
204
209
|
<td>=</td>
|
205
|
-
<td class="context-item-value">'Location'</td>
|
210
|
+
<td class="context-item-value">'Location'.freeze</td>
|
211
|
+
</tr>
|
212
|
+
<tr class="top-aligned-row context-row">
|
213
|
+
<td class="context-item-name">Cookie</td>
|
214
|
+
<td>=</td>
|
215
|
+
<td class="context-item-value">'Cookie'</td>
|
216
|
+
</tr>
|
217
|
+
<tr class="top-aligned-row context-row">
|
218
|
+
<td class="context-item-name">SetCookie</td>
|
219
|
+
<td>=</td>
|
220
|
+
<td class="context-item-value">"Set-Cookie: %s=%s; path=/; expires=%s\r\n".freeze</td>
|
221
|
+
</tr>
|
222
|
+
<tr class="top-aligned-row context-row">
|
223
|
+
<td class="context-item-name">CookieSplit</td>
|
224
|
+
<td>=</td>
|
225
|
+
<td class="context-item-value">/[;,] */n.freeze</td>
|
226
|
+
</tr>
|
227
|
+
<tr class="top-aligned-row context-row">
|
228
|
+
<td class="context-item-name">CookieRegexp</td>
|
229
|
+
<td>=</td>
|
230
|
+
<td class="context-item-value">/\s*(.+)=(.*)\s*/.freeze</td>
|
231
|
+
</tr>
|
232
|
+
<tr class="top-aligned-row context-row">
|
233
|
+
<td class="context-item-name">CookieExpiredTime</td>
|
234
|
+
<td>=</td>
|
235
|
+
<td class="context-item-value">Time.at(0).freeze</td>
|
206
236
|
</tr>
|
207
237
|
</table>
|
208
238
|
</div>
|