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
data/CHANGELOG
CHANGED
@@ -1,4 +1,22 @@
|
|
1
|
-
|
1
|
+
==0.2.7
|
2
|
+
|
3
|
+
* Wrote spec for HTTP::Connection.
|
4
|
+
|
5
|
+
* Added spec files to rake stats reporting.
|
6
|
+
|
7
|
+
* Changed @conn to @socket in both HTTP::Connection and HTTP::Request for better readability.
|
8
|
+
|
9
|
+
* Wrote functional test for request body (but at least some of the testing should be in a unit test.)
|
10
|
+
|
11
|
+
* Added request body parsing (both URL-encoded and multipart.)
|
12
|
+
|
13
|
+
* Moved all HTTP::Const constants into HTTP::Request.
|
14
|
+
|
15
|
+
* Added Date to response headers. This is needed for caching to work correctly.
|
16
|
+
|
17
|
+
* Fixed bug in serverside script that caused an exception when specifying port number.
|
18
|
+
|
19
|
+
==0.2.6
|
2
20
|
|
3
21
|
* Refactored HTTP-related code into a new HTTP::Request class and a simplified HTTP::Connection.
|
4
22
|
|
@@ -8,7 +26,7 @@
|
|
8
26
|
|
9
27
|
* Fixed minor documentation error.
|
10
28
|
|
11
|
-
|
29
|
+
==0.2.5
|
12
30
|
|
13
31
|
* Added template serving to static file module.
|
14
32
|
|
@@ -30,7 +48,7 @@
|
|
30
48
|
|
31
49
|
* Added /test/spec directory.
|
32
50
|
|
33
|
-
|
51
|
+
==0.2.0
|
34
52
|
|
35
53
|
* Updated RFuzz script to work, but it doesn't still do anything interesting.
|
36
54
|
|
@@ -96,25 +114,15 @@
|
|
96
114
|
|
97
115
|
* Added HTTP parsing code with unit tests.
|
98
116
|
|
99
|
-
* Started adding request code.
|
100
|
-
|
101
117
|
* More unit tests for application code.
|
102
118
|
|
103
119
|
* Basic server code works with unit tests.
|
104
120
|
|
105
|
-
* Started work on application code.
|
106
|
-
|
107
121
|
* Added option parsing to serverside script.
|
108
122
|
|
109
123
|
* Added daemon code and unit tests.
|
110
124
|
|
111
|
-
|
112
|
-
|
113
|
-
* Created Gem spec.
|
114
|
-
|
115
|
-
* Created directory structure.
|
116
|
-
|
117
|
-
*Mongrel-based branch*
|
125
|
+
==0.1
|
118
126
|
|
119
127
|
* Added host attribute to Controller::Request.
|
120
128
|
|
@@ -149,5 +157,3 @@
|
|
149
157
|
* Imported extensions from Reality project.
|
150
158
|
|
151
159
|
* Implemented daemon and server cluster.
|
152
|
-
|
153
|
-
* Basic configuration infrastructure is ready.
|
data/Rakefile
CHANGED
@@ -7,7 +7,7 @@ require 'fileutils'
|
|
7
7
|
include FileUtils
|
8
8
|
|
9
9
|
NAME = "serverside"
|
10
|
-
VERS = "0.2.
|
10
|
+
VERS = "0.2.7"
|
11
11
|
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
12
12
|
RDOC_OPTS = ['--quiet', '--title', "ServerSide Documentation",
|
13
13
|
"--opname", "index.html",
|
@@ -109,14 +109,21 @@ task :aok do
|
|
109
109
|
sh %{rake spec}
|
110
110
|
end
|
111
111
|
|
112
|
+
desc 'Update docs and upload to rubyforge.org'
|
113
|
+
task :doc_rforge do
|
114
|
+
sh %{rake doc}
|
115
|
+
sh "scp -C -r * ciconia@rubyforge.org:/var/www/gforge-projects/serverside/"
|
116
|
+
end
|
117
|
+
|
112
118
|
##############################################################################
|
113
119
|
# Statistics
|
114
120
|
##############################################################################
|
115
121
|
|
116
122
|
STATS_DIRECTORIES = [
|
117
|
-
%w(Code
|
118
|
-
%w(Unit\ tests
|
119
|
-
%w(Functional\ tests
|
123
|
+
%w(Code lib/),
|
124
|
+
%w(Unit\ tests test/unit),
|
125
|
+
%w(Functional\ tests test/functional),
|
126
|
+
%w(Specification\ tests test/spec)
|
120
127
|
].collect { |name, dir| [ name, "./#{dir}" ] }.select { |name, dir| File.directory?(dir) }
|
121
128
|
|
122
129
|
desc "Report code statistics (KLOCs, etc) from the application"
|
data/bin/serverside
CHANGED
@@ -26,7 +26,7 @@ that directory. If no path is given, the current working directory is assumed."
|
|
26
26
|
$cmd_config[:host] = v
|
27
27
|
end
|
28
28
|
opts.on("-p", "--port NUM", "Port or port range (default is 8000)") do |v|
|
29
|
-
$cmd_config[:ports] = (v =~ /\.\./) ? eval(v) : v.to_i..
|
29
|
+
$cmd_config[:ports] = (v =~ /\.\./) ? eval(v) : v.to_i..v.to_i
|
30
30
|
end
|
31
31
|
|
32
32
|
# No argument, shows at tail. This will print an options summary.
|
@@ -55,13 +55,13 @@
|
|
55
55
|
<tr class="top-aligned-row">
|
56
56
|
<td><strong>In:</strong></td>
|
57
57
|
<td>
|
58
|
-
<a href="../files/lib/serverside/cluster_rb.html">
|
59
|
-
lib/serverside/cluster.rb
|
60
|
-
</a>
|
61
|
-
<br />
|
62
58
|
<a href="../files/lib/serverside/daemon_rb.html">
|
63
59
|
lib/serverside/daemon.rb
|
64
60
|
</a>
|
61
|
+
<br />
|
62
|
+
<a href="../files/lib/serverside/cluster_rb.html">
|
63
|
+
lib/serverside/cluster.rb
|
64
|
+
</a>
|
65
65
|
<br />
|
66
66
|
</td>
|
67
67
|
</tr>
|
@@ -58,6 +58,10 @@
|
|
58
58
|
<a href="../files/lib/serverside_rb.html">
|
59
59
|
lib/serverside.rb
|
60
60
|
</a>
|
61
|
+
<br />
|
62
|
+
<a href="../files/lib/serverside/server_rb.html">
|
63
|
+
lib/serverside/server.rb
|
64
|
+
</a>
|
61
65
|
<br />
|
62
66
|
<a href="../files/lib/serverside/application_rb.html">
|
63
67
|
lib/serverside/application.rb
|
@@ -67,25 +71,21 @@
|
|
67
71
|
lib/serverside/connection.rb
|
68
72
|
</a>
|
69
73
|
<br />
|
70
|
-
<a href="../files/lib/serverside/
|
71
|
-
lib/serverside/
|
74
|
+
<a href="../files/lib/serverside/static_rb.html">
|
75
|
+
lib/serverside/static.rb
|
72
76
|
</a>
|
73
77
|
<br />
|
74
78
|
<a href="../files/lib/serverside/routing_rb.html">
|
75
79
|
lib/serverside/routing.rb
|
76
80
|
</a>
|
77
|
-
<br />
|
78
|
-
<a href="../files/lib/serverside/server_rb.html">
|
79
|
-
lib/serverside/server.rb
|
80
|
-
</a>
|
81
|
-
<br />
|
82
|
-
<a href="../files/lib/serverside/static_rb.html">
|
83
|
-
lib/serverside/static.rb
|
84
|
-
</a>
|
85
81
|
<br />
|
86
82
|
<a href="../files/lib/serverside/template_rb.html">
|
87
83
|
lib/serverside/template.rb
|
88
84
|
</a>
|
85
|
+
<br />
|
86
|
+
<a href="../files/lib/serverside/request_rb.html">
|
87
|
+
lib/serverside/request.rb
|
88
|
+
</a>
|
89
89
|
<br />
|
90
90
|
</td>
|
91
91
|
</tr>
|
@@ -55,6 +55,10 @@
|
|
55
55
|
<tr class="top-aligned-row">
|
56
56
|
<td><strong>In:</strong></td>
|
57
57
|
<td>
|
58
|
+
<a href="../../files/lib/serverside/server_rb.html">
|
59
|
+
lib/serverside/server.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
58
62
|
<a href="../../files/lib/serverside/connection_rb.html">
|
59
63
|
lib/serverside/connection.rb
|
60
64
|
</a>
|
@@ -62,10 +66,6 @@
|
|
62
66
|
<a href="../../files/lib/serverside/request_rb.html">
|
63
67
|
lib/serverside/request.rb
|
64
68
|
</a>
|
65
|
-
<br />
|
66
|
-
<a href="../../files/lib/serverside/server_rb.html">
|
67
|
-
lib/serverside/server.rb
|
68
|
-
</a>
|
69
69
|
<br />
|
70
70
|
</td>
|
71
71
|
</tr>
|
@@ -95,8 +95,7 @@
|
|
95
95
|
<div id="class-list">
|
96
96
|
<h3 class="section-bar">Classes and Modules</h3>
|
97
97
|
|
98
|
-
|
99
|
-
Class <a href="HTTP/Connection.html" class="link">ServerSide::HTTP::Connection</a><br />
|
98
|
+
Class <a href="HTTP/Connection.html" class="link">ServerSide::HTTP::Connection</a><br />
|
100
99
|
Class <a href="HTTP/Request.html" class="link">ServerSide::HTTP::Request</a><br />
|
101
100
|
Class <a href="HTTP/Server.html" class="link">ServerSide::HTTP::Server</a><br />
|
102
101
|
|
@@ -98,8 +98,8 @@ implementing <a href="../HTTP.html">HTTP</a> 1.1 persistent connections.
|
|
98
98
|
<h3 class="section-bar">Methods</h3>
|
99
99
|
|
100
100
|
<div class="name-list">
|
101
|
-
<a href="#
|
102
|
-
<a href="#
|
101
|
+
<a href="#M000040">new</a>
|
102
|
+
<a href="#M000041">process</a>
|
103
103
|
</div>
|
104
104
|
</div>
|
105
105
|
|
@@ -121,12 +121,12 @@ implementing <a href="../HTTP.html">HTTP</a> 1.1 persistent connections.
|
|
121
121
|
<div id="methods">
|
122
122
|
<h3 class="section-bar">Public Class methods</h3>
|
123
123
|
|
124
|
-
<div id="method-
|
125
|
-
<a name="
|
124
|
+
<div id="method-M000040" class="method-detail">
|
125
|
+
<a name="M000040"></a>
|
126
126
|
|
127
127
|
<div class="method-heading">
|
128
|
-
<a href="#
|
129
|
-
<span class="method-name">new</span><span class="method-args">(
|
128
|
+
<a href="#M000040" class="method-signature">
|
129
|
+
<span class="method-name">new</span><span class="method-args">(socket, request_class)</span>
|
130
130
|
</a>
|
131
131
|
</div>
|
132
132
|
|
@@ -136,12 +136,12 @@ Initializes the request instance. A new thread is created for processing
|
|
136
136
|
requests.
|
137
137
|
</p>
|
138
138
|
<p><a class="source-toggle" href="#"
|
139
|
-
onclick="toggleCode('
|
140
|
-
<div class="method-source-code" id="
|
139
|
+
onclick="toggleCode('M000040-source');return false;">[Source]</a></p>
|
140
|
+
<div class="method-source-code" id="M000040-source">
|
141
141
|
<pre>
|
142
142
|
<span class="ruby-comment cmt"># File lib/serverside/connection.rb, line 13</span>
|
143
|
-
13: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">
|
144
|
-
14: <span class="ruby-ivar">@
|
143
|
+
13: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">socket</span>, <span class="ruby-identifier">request_class</span>)
|
144
|
+
14: <span class="ruby-ivar">@socket</span>, <span class="ruby-ivar">@request_class</span> = <span class="ruby-identifier">socket</span>, <span class="ruby-identifier">request_class</span>
|
145
145
|
15: <span class="ruby-ivar">@thread</span> = <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span> {<span class="ruby-identifier">process</span>}
|
146
146
|
16: <span class="ruby-keyword kw">end</span>
|
147
147
|
</pre>
|
@@ -151,11 +151,11 @@ requests.
|
|
151
151
|
|
152
152
|
<h3 class="section-bar">Public Instance methods</h3>
|
153
153
|
|
154
|
-
<div id="method-
|
155
|
-
<a name="
|
154
|
+
<div id="method-M000041" class="method-detail">
|
155
|
+
<a name="M000041"></a>
|
156
156
|
|
157
157
|
<div class="method-heading">
|
158
|
-
<a href="#
|
158
|
+
<a href="#M000041" class="method-signature">
|
159
159
|
<span class="method-name">process</span><span class="method-args">()</span>
|
160
160
|
</a>
|
161
161
|
</div>
|
@@ -167,19 +167,21 @@ error occurs, or the connection is not persistent, the connection is
|
|
167
167
|
closed.
|
168
168
|
</p>
|
169
169
|
<p><a class="source-toggle" href="#"
|
170
|
-
onclick="toggleCode('
|
171
|
-
<div class="method-source-code" id="
|
170
|
+
onclick="toggleCode('M000041-source');return false;">[Source]</a></p>
|
171
|
+
<div class="method-source-code" id="M000041-source">
|
172
172
|
<pre>
|
173
173
|
<span class="ruby-comment cmt"># File lib/serverside/connection.rb, line 21</span>
|
174
174
|
21: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">process</span>
|
175
175
|
22: <span class="ruby-keyword kw">while</span> <span class="ruby-keyword kw">true</span>
|
176
|
-
23: <span class="ruby-
|
177
|
-
24:
|
178
|
-
25:
|
179
|
-
26: <span class="ruby-
|
180
|
-
27: <span class="ruby-keyword kw">
|
181
|
-
28: <span class="ruby-
|
182
|
-
29: <span class="ruby-keyword kw">
|
176
|
+
23: <span class="ruby-comment cmt"># the process function is expected to return true or a non-nil value</span>
|
177
|
+
24: <span class="ruby-comment cmt"># if the connection is to persist.</span>
|
178
|
+
25: <span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@request_class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@socket</span>).<span class="ruby-identifier">process</span>
|
179
|
+
26: <span class="ruby-keyword kw">end</span>
|
180
|
+
27: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
181
|
+
28: <span class="ruby-comment cmt"># We don't care. Just close the connection.</span>
|
182
|
+
29: <span class="ruby-keyword kw">ensure</span>
|
183
|
+
30: <span class="ruby-ivar">@socket</span>.<span class="ruby-identifier">close</span>
|
184
|
+
31: <span class="ruby-keyword kw">end</span>
|
183
185
|
</pre>
|
184
186
|
</div>
|
185
187
|
</div>
|
@@ -82,12 +82,12 @@
|
|
82
82
|
|
83
83
|
<div id="description">
|
84
84
|
<p>
|
85
|
-
The
|
86
|
-
requests. The request class contains methods
|
87
|
-
rendering a response. <a
|
88
|
-
|
89
|
-
|
90
|
-
connection is closed.
|
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
91
|
</p>
|
92
92
|
|
93
93
|
</div>
|
@@ -99,16 +99,17 @@ connection is closed.
|
|
99
99
|
<h3 class="section-bar">Methods</h3>
|
100
100
|
|
101
101
|
<div class="name-list">
|
102
|
-
<a href="#
|
102
|
+
<a href="#M000039">delete_cookie</a>
|
103
103
|
<a href="#M000029">new</a>
|
104
104
|
<a href="#M000031">parse</a>
|
105
|
+
<a href="#M000034">parse_body</a>
|
105
106
|
<a href="#M000033">parse_cookies</a>
|
106
107
|
<a href="#M000032">parse_parameters</a>
|
107
108
|
<a href="#M000030">process</a>
|
108
|
-
<a href="#
|
109
|
-
<a href="#
|
110
|
-
<a href="#
|
111
|
-
<a href="#
|
109
|
+
<a href="#M000036">redirect</a>
|
110
|
+
<a href="#M000035">send_response</a>
|
111
|
+
<a href="#M000038">set_cookie</a>
|
112
|
+
<a href="#M000037">stream</a>
|
112
113
|
</div>
|
113
114
|
</div>
|
114
115
|
|
@@ -127,6 +128,181 @@ connection is closed.
|
|
127
128
|
<div id="section">
|
128
129
|
|
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">"\r\n".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"> </td>
|
146
|
+
<td class="context-item-desc">
|
147
|
+
Here’s a nice one - parses the first line of a request. The expected
|
148
|
+
format is as follows: <method> </path>[/][?<query>] <a
|
149
|
+
href="../HTTP.html">HTTP</a>/<version>
|
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"> </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">'&'.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"> </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">"HTTP/1.1 %d\r\nDate: %s\r\nConnection: close\r\nContent-Type: %s\r\n%s%sContent-Length: %d\r\n\r\n".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">"HTTP/1.1 %d\r\nDate: %s\r\nConnection: close\r\nContent-Type: %s\r\n%s%s\r\n".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">"HTTP/1.1 %d\r\nDate: %s\r\nContent-Type: %s\r\n%s%sContent-Length: %d\r\n\r\n".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">"HTTP/1.1 %d\r\nDate: %s\r\nConnection: close\r\nLocation: %s\r\n\r\n".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">"%s: %s\r\n".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">"Set-Cookie: %s=%s; path=/; expires=%s\r\n".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">"Content-Type".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=\"?([^\";,]+)/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+)=\"([^\"]*)/.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>
|
130
306
|
|
131
307
|
|
132
308
|
|
@@ -136,7 +312,17 @@ connection is closed.
|
|
136
312
|
<div class="name-list">
|
137
313
|
<table>
|
138
314
|
<tr class="top-aligned-row context-row">
|
139
|
-
<td class="context-item-name">
|
315
|
+
<td class="context-item-name">body</td>
|
316
|
+
<td class="context-item-value"> [R] </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"> [R] </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>
|
140
326
|
<td class="context-item-value"> [R] </td>
|
141
327
|
<td class="context-item-desc"></td>
|
142
328
|
</tr>
|
@@ -180,6 +366,11 @@ connection is closed.
|
|
180
366
|
<td class="context-item-value"> [R] </td>
|
181
367
|
<td class="context-item-desc"></td>
|
182
368
|
</tr>
|
369
|
+
<tr class="top-aligned-row context-row">
|
370
|
+
<td class="context-item-name">socket</td>
|
371
|
+
<td class="context-item-value"> [R] </td>
|
372
|
+
<td class="context-item-desc"></td>
|
373
|
+
</tr>
|
183
374
|
<tr class="top-aligned-row context-row">
|
184
375
|
<td class="context-item-name">version</td>
|
185
376
|
<td class="context-item-value"> [R] </td>
|
@@ -200,7 +391,7 @@ connection is closed.
|
|
200
391
|
|
201
392
|
<div class="method-heading">
|
202
393
|
<a href="#M000029" class="method-signature">
|
203
|
-
<span class="method-name">new</span><span class="method-args">(
|
394
|
+
<span class="method-name">new</span><span class="method-args">(socket)</span>
|
204
395
|
</a>
|
205
396
|
</div>
|
206
397
|
|
@@ -208,16 +399,16 @@ connection is closed.
|
|
208
399
|
<p>
|
209
400
|
Initializes the request instance. Any descendants of <a
|
210
401
|
href="Request.html">HTTP::Request</a> which override the initialize method
|
211
|
-
must receive
|
402
|
+
must receive socket as the single argument, and copy it to @socket.
|
212
403
|
</p>
|
213
404
|
<p><a class="source-toggle" href="#"
|
214
405
|
onclick="toggleCode('M000029-source');return false;">[Source]</a></p>
|
215
406
|
<div class="method-source-code" id="M000029-source">
|
216
407
|
<pre>
|
217
|
-
<span class="ruby-comment cmt"># File lib/serverside/request.rb, line
|
218
|
-
|
219
|
-
|
220
|
-
|
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>
|
221
412
|
</pre>
|
222
413
|
</div>
|
223
414
|
</div>
|
@@ -225,11 +416,11 @@ must receive conn as the single argument, and copy it to @conn.
|
|
225
416
|
|
226
417
|
<h3 class="section-bar">Public Instance methods</h3>
|
227
418
|
|
228
|
-
<div id="method-
|
229
|
-
<a name="
|
419
|
+
<div id="method-M000039" class="method-detail">
|
420
|
+
<a name="M000039"></a>
|
230
421
|
|
231
422
|
<div class="method-heading">
|
232
|
-
<a href="#
|
423
|
+
<a href="#M000039" class="method-signature">
|
233
424
|
<span class="method-name">delete_cookie</span><span class="method-args">(name)</span>
|
234
425
|
</a>
|
235
426
|
</div>
|
@@ -240,13 +431,13 @@ Marks a cookie as deleted. The cookie is given an expires stamp in the
|
|
240
431
|
past.
|
241
432
|
</p>
|
242
433
|
<p><a class="source-toggle" href="#"
|
243
|
-
onclick="toggleCode('
|
244
|
-
<div class="method-source-code" id="
|
434
|
+
onclick="toggleCode('M000039-source');return false;">[Source]</a></p>
|
435
|
+
<div class="method-source-code" id="M000039-source">
|
245
436
|
<pre>
|
246
|
-
<span class="ruby-comment cmt"># File lib/serverside/request.rb, line
|
247
|
-
|
248
|
-
|
249
|
-
|
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>
|
250
441
|
</pre>
|
251
442
|
</div>
|
252
443
|
</div>
|
@@ -273,25 +464,79 @@ href="Connection.html">Connection</a>’ header).
|
|
273
464
|
onclick="toggleCode('M000031-source');return false;">[Source]</a></p>
|
274
465
|
<div class="method-source-code" id="M000031-source">
|
275
466
|
<pre>
|
276
|
-
<span class="ruby-comment cmt"># File lib/serverside/request.rb, line
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
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">&&</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">"--#$1"</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">"\r\n\r\n"</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>
|
295
540
|
</pre>
|
296
541
|
</div>
|
297
542
|
</div>
|
@@ -314,15 +559,15 @@ Parses cookie values passed in the request
|
|
314
559
|
onclick="toggleCode('M000033-source');return false;">[Source]</a></p>
|
315
560
|
<div class="method-source-code" id="M000033-source">
|
316
561
|
<pre>
|
317
|
-
<span class="ruby-comment cmt"># File lib/serverside/request.rb, line
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
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>
|
326
571
|
</pre>
|
327
572
|
</div>
|
328
573
|
</div>
|
@@ -346,15 +591,15 @@ parameter values.
|
|
346
591
|
onclick="toggleCode('M000032-source');return false;">[Source]</a></p>
|
347
592
|
<div class="method-source-code" id="M000032-source">
|
348
593
|
<pre>
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
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>
|
358
603
|
</pre>
|
359
604
|
</div>
|
360
605
|
</div>
|
@@ -377,20 +622,20 @@ Processes the request by parsing it and then responding.
|
|
377
622
|
onclick="toggleCode('M000030-source');return false;">[Source]</a></p>
|
378
623
|
<div class="method-source-code" id="M000030-source">
|
379
624
|
<pre>
|
380
|
-
<span class="ruby-comment cmt"># File lib/serverside/request.rb, line
|
381
|
-
|
382
|
-
|
383
|
-
|
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">&&</span> ((<span class="ruby-identifier">respond</span> <span class="ruby-operator">||</span> <span class="ruby-keyword kw">true</span>) <span class="ruby-operator">&&</span> <span class="ruby-ivar">@persistent</span>)
|
628
|
+
62: <span class="ruby-keyword kw">end</span>
|
384
629
|
</pre>
|
385
630
|
</div>
|
386
631
|
</div>
|
387
632
|
</div>
|
388
633
|
|
389
|
-
<div id="method-
|
390
|
-
<a name="
|
634
|
+
<div id="method-M000036" class="method-detail">
|
635
|
+
<a name="M000036"></a>
|
391
636
|
|
392
637
|
<div class="method-heading">
|
393
|
-
<a href="#
|
638
|
+
<a href="#M000036" class="method-signature">
|
394
639
|
<span class="method-name">redirect</span><span class="method-args">(location, permanent = false)</span>
|
395
640
|
</a>
|
396
641
|
</div>
|
@@ -400,26 +645,27 @@ Processes the request by parsing it and then responding.
|
|
400
645
|
Send a redirect response.
|
401
646
|
</p>
|
402
647
|
<p><a class="source-toggle" href="#"
|
403
|
-
onclick="toggleCode('
|
404
|
-
<div class="method-source-code" id="
|
648
|
+
onclick="toggleCode('M000036-source');return false;">[Source]</a></p>
|
649
|
+
<div class="method-source-code" id="M000036-source">
|
405
650
|
<pre>
|
406
|
-
<span class="ruby-comment cmt"># File lib/serverside/request.rb, line
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
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"><<</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>
|
413
659
|
</pre>
|
414
660
|
</div>
|
415
661
|
</div>
|
416
662
|
</div>
|
417
663
|
|
418
|
-
<div id="method-
|
419
|
-
<a name="
|
664
|
+
<div id="method-M000035" class="method-detail">
|
665
|
+
<a name="M000035"></a>
|
420
666
|
|
421
667
|
<div class="method-heading">
|
422
|
-
<a href="#
|
668
|
+
<a href="#M000035" class="method-signature">
|
423
669
|
<span class="method-name">send_response</span><span class="method-args">(status, content_type, body = nil, content_length = nil, headers = nil)</span>
|
424
670
|
</a>
|
425
671
|
</div>
|
@@ -429,36 +675,36 @@ Send a redirect response.
|
|
429
675
|
Sends an <a href="../HTTP.html">HTTP</a> response.
|
430
676
|
</p>
|
431
677
|
<p><a class="source-toggle" href="#"
|
432
|
-
onclick="toggleCode('
|
433
|
-
<div class="method-source-code" id="
|
678
|
+
onclick="toggleCode('M000035-source');return false;">[Source]</a></p>
|
679
|
+
<div class="method-source-code" id="M000035-source">
|
434
680
|
<pre>
|
435
|
-
<span class="ruby-comment cmt"># File lib/serverside/request.rb, line
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
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"><<</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">&&</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"><<</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"><<</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>
|
452
698
|
</pre>
|
453
699
|
</div>
|
454
700
|
</div>
|
455
701
|
</div>
|
456
702
|
|
457
|
-
<div id="method-
|
458
|
-
<a name="
|
703
|
+
<div id="method-M000038" class="method-detail">
|
704
|
+
<a name="M000038"></a>
|
459
705
|
|
460
706
|
<div class="method-heading">
|
461
|
-
<a href="#
|
707
|
+
<a href="#M000038" class="method-signature">
|
462
708
|
<span class="method-name">set_cookie</span><span class="method-args">(name, value, expires)</span>
|
463
709
|
</a>
|
464
710
|
</div>
|
@@ -468,24 +714,24 @@ Sends an <a href="../HTTP.html">HTTP</a> response.
|
|
468
714
|
Sets a cookie to be included in the response.
|
469
715
|
</p>
|
470
716
|
<p><a class="source-toggle" href="#"
|
471
|
-
onclick="toggleCode('
|
472
|
-
<div class="method-source-code" id="
|
717
|
+
onclick="toggleCode('M000038-source');return false;">[Source]</a></p>
|
718
|
+
<div class="method-source-code" id="M000038-source">
|
473
719
|
<pre>
|
474
|
-
<span class="ruby-comment cmt"># File lib/serverside/request.rb, line
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
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">""</span>
|
723
|
+
181: <span class="ruby-ivar">@response_cookies</span> <span class="ruby-operator"><<</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>
|
479
725
|
</pre>
|
480
726
|
</div>
|
481
727
|
</div>
|
482
728
|
</div>
|
483
729
|
|
484
|
-
<div id="method-
|
485
|
-
<a name="
|
730
|
+
<div id="method-M000037" class="method-detail">
|
731
|
+
<a name="M000037"></a>
|
486
732
|
|
487
733
|
<div class="method-heading">
|
488
|
-
<a href="#
|
734
|
+
<a href="#M000037" class="method-signature">
|
489
735
|
<span class="method-name">stream</span><span class="method-args">(body)</span>
|
490
736
|
</a>
|
491
737
|
</div>
|
@@ -495,13 +741,13 @@ Sets a cookie to be included in the response.
|
|
495
741
|
Streams additional data to the client.
|
496
742
|
</p>
|
497
743
|
<p><a class="source-toggle" href="#"
|
498
|
-
onclick="toggleCode('
|
499
|
-
<div class="method-source-code" id="
|
744
|
+
onclick="toggleCode('M000037-source');return false;">[Source]</a></p>
|
745
|
+
<div class="method-source-code" id="M000037-source">
|
500
746
|
<pre>
|
501
|
-
<span class="ruby-comment cmt"># File lib/serverside/request.rb, line
|
502
|
-
|
503
|
-
|
504
|
-
|
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"><<</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>
|
505
751
|
</pre>
|
506
752
|
</div>
|
507
753
|
</div>
|