narf 0.5.1 → 0.6.1
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 +44 -0
- data/README +6 -2
- data/README~ +124 -0
- data/build.rb +3 -2
- data/build.rb~ +1 -1
- data/doc/apache_cgi.txt +1 -5
- data/doc/apache_cgi.txt~ +17 -0
- data/doc/fastcgi.txt +1 -1
- data/doc/fastcgi.txt~ +19 -0
- data/doc/rdoc/classes/Web.html +9 -6
- data/doc/rdoc/classes/Web.src/M000002.html +1 -1
- data/doc/rdoc/classes/Web.src/M000003.html +1 -1
- data/doc/rdoc/classes/Web.src/M000004.html +1 -1
- data/doc/rdoc/classes/Web.src/M000005.html +1 -1
- data/doc/rdoc/classes/Web.src/M000006.html +1 -1
- data/doc/rdoc/classes/Web.src/M000007.html +1 -1
- data/doc/rdoc/classes/Web.src/M000008.html +1 -1
- data/doc/rdoc/classes/Web.src/M000009.html +1 -1
- data/doc/rdoc/classes/Web/CGD.src/M000038.html +2 -1
- data/doc/rdoc/classes/Web/CGD.src/M000039.html +1 -1
- data/doc/rdoc/classes/Web/CGD.src/M000040.html +1 -1
- data/doc/rdoc/classes/Web/CGD.src/M000041.html +1 -1
- data/doc/rdoc/classes/Web/CGI.src/M000105.html +1 -1
- data/doc/rdoc/classes/Web/CGI.src/M000106.html +1 -1
- data/doc/rdoc/classes/Web/CGI.src/M000107.html +1 -1
- data/doc/rdoc/classes/Web/Narflates.html +4 -2
- data/doc/rdoc/classes/Web/Testing.src/M000027.html +1 -4
- data/doc/rdoc/classes/Web/Testing.src/M000028.html +1 -2
- data/doc/rdoc/classes/Web/Testing.src/M000029.html +1 -1
- data/doc/rdoc/classes/Web/Testing.src/M000030.html +1 -1
- data/doc/rdoc/classes/Web/Testing.src/M000031.html +1 -1
- data/doc/rdoc/classes/Web/Testing.src/M000032.html +1 -1
- data/doc/rdoc/classes/Web/Testing.src/M000033.html +1 -1
- data/doc/rdoc/classes/Web/Testing.src/M000034.html +1 -1
- data/doc/rdoc/classes/Web/Testing.src/M000035.html +1 -1
- data/doc/rdoc/classes/Web/Testing.src/M000036.html +1 -1
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/README.html +7 -3
- data/doc/rdoc/files/doc/apache_cgi_txt.html +3 -9
- data/doc/rdoc/files/doc/fastcgi_txt.html +2 -2
- data/doc/rdoc/files/lib/web/cgi_rb.html +1 -1
- data/doc/rdoc/files/lib/web/parser_rb.html +1 -1
- data/doc/rdoc/files/lib/web/template_rb.html +1 -1
- data/doc/rdoc/files/lib/web/testing_rb.html +1 -1
- data/doc/rdoc/files/lib/web/wiki_rb.html +1 -1
- data/doc/rdoc/files/lib/web_rb.html +1 -1
- data/lib/web.rb +127 -20
- data/lib/web/parser.rb +25 -7
- data/lib/web/parser.rb~ +30 -8
- data/lib/web/template.rb +6 -4
- data/lib/web/wiki.rb +23 -12
- data/lib/web/wiki.rb~ +1 -1
- data/narf-0.5.1.gem +0 -0
- data/narf.gemspec +1 -1
- data/narf.gemspec~ +18 -30
- data/test/test.request.rb +33 -20
- data/test/test.request.rb~ +10 -0
- data/test/testfiles/mac_ie_env.yaml +32 -0
- data/test/testfiles/mac_ie_stdin.bin +0 -0
- data/test/testfiles/mac_safari_stdin.bin +0 -0
- data/test/wiki/test.tarpit.rb +16 -0
- data/test/wiki/test.tarpit.rb~ +40 -0
- metadata +9 -3
- data/vandals.test.txt +0 -3
@@ -7,7 +7,7 @@
|
|
7
7
|
<link rel=StyleSheet href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
8
8
|
</head>
|
9
9
|
<body bgcolor="white">
|
10
|
-
<pre><span class="cmt"># File lib/web/cgi.rb, line
|
10
|
+
<pre><span class="cmt"># File lib/web/cgi.rb, line 629</span>
|
11
11
|
<span class="kw">def</span> CGI::process( options={}, &block )
|
12
12
|
<span class="kw">if</span> CGI::server_sniff == :fcgi
|
13
13
|
FCGI::each_request{ |fcgi|
|
@@ -79,14 +79,16 @@ template merged with values:
|
|
79
79
|
</p>
|
80
80
|
<pre>
|
81
81
|
--- script.rb:
|
82
|
-
Web
|
82
|
+
Web::process do
|
83
|
+
Web.print_template "mytemplate.html",
|
83
84
|
"field1" => "val1",
|
84
85
|
"field2" => "val2",
|
85
|
-
|
86
|
+
"field3" => "val3",
|
86
87
|
"field4" => "3",
|
87
88
|
"values" => [{ "name" => "one", "value" => "1"},
|
88
89
|
{ "name" => "two", "value" => "2"},
|
89
90
|
{ "name' => "three", "value" => "3"}]
|
91
|
+
end
|
90
92
|
|
91
93
|
--- mytemplate.html:
|
92
94
|
<narf:input type="text" name="field1">
|
@@ -19,10 +19,7 @@
|
|
19
19
|
|
20
20
|
options[:path_info] = path_info
|
21
21
|
options[:script_name] = script_name
|
22
|
-
|
23
|
-
Web.set_cgi CGI.new(options)
|
24
|
-
|
25
|
-
load_request( script_path, webpath )
|
22
|
+
load_request( options, script_path, webpath )
|
26
23
|
<span class="kw">end</span></pre>
|
27
24
|
</body>
|
28
25
|
</html>
|
@@ -50,9 +50,8 @@
|
|
50
50
|
|
51
51
|
options[:path_info] = path_info <span class="cmt">#oldRequest.path_info</span>
|
52
52
|
options[:script_name] = script_name <span class="cmt">#oldRequest.script_name</span>
|
53
|
-
Web.set_cgi CGI.new( options )
|
54
53
|
|
55
|
-
load_request( script_path, webpath )
|
54
|
+
load_request( options, script_path, webpath )
|
56
55
|
<span class="kw">end</span></pre>
|
57
56
|
</body>
|
58
57
|
</html>
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<link rel=StyleSheet href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
8
8
|
</head>
|
9
9
|
<body bgcolor="white">
|
10
|
-
<pre><span class="cmt"># File lib/web/testing.rb, line
|
10
|
+
<pre><span class="cmt"># File lib/web/testing.rb, line 325</span>
|
11
11
|
<span class="kw">def</span> assert_template_used filename, msg=<span class="str">""</span>
|
12
12
|
Web.assert_template_used filename, msg
|
13
13
|
<span class="kw">end</span></pre>
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<link rel=StyleSheet href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
8
8
|
</head>
|
9
9
|
<body bgcolor="white">
|
10
|
-
<pre><span class="cmt"># File lib/web/testing.rb, line
|
10
|
+
<pre><span class="cmt"># File lib/web/testing.rb, line 330</span>
|
11
11
|
<span class="kw">def</span> assert_template_not_used filename, msg=<span class="str">""</span>
|
12
12
|
Web.assert_template_not_used filename, msg
|
13
13
|
<span class="kw">end</span></pre>
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<link rel=StyleSheet href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
8
8
|
</head>
|
9
9
|
<body bgcolor="white">
|
10
|
-
<pre><span class="cmt"># File lib/web/testing.rb, line
|
10
|
+
<pre><span class="cmt"># File lib/web/testing.rb, line 335</span>
|
11
11
|
<span class="kw">def</span> assert_vars_includes expected
|
12
12
|
Web.assert_vars_includes expected
|
13
13
|
<span class="kw">end</span></pre>
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<link rel=StyleSheet href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
8
8
|
</head>
|
9
9
|
<body bgcolor="white">
|
10
|
-
<pre><span class="cmt"># File lib/web/testing.rb, line
|
10
|
+
<pre><span class="cmt"># File lib/web/testing.rb, line 340</span>
|
11
11
|
<span class="kw">def</span> assert_form_includes formname, expected
|
12
12
|
Web.assert_form_includes formname, expected
|
13
13
|
<span class="kw">end</span></pre>
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<link rel=StyleSheet href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
8
8
|
</head>
|
9
9
|
<body bgcolor="white">
|
10
|
-
<pre><span class="cmt"># File lib/web/testing.rb, line
|
10
|
+
<pre><span class="cmt"># File lib/web/testing.rb, line 345</span>
|
11
11
|
<span class="kw">def</span> assert_content expected, msg=<span class="str">""</span>
|
12
12
|
Web.assert_content expected, msg
|
13
13
|
<span class="kw">end</span></pre>
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<link rel=StyleSheet href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
8
8
|
</head>
|
9
9
|
<body bgcolor="white">
|
10
|
-
<pre><span class="cmt"># File lib/web/testing.rb, line
|
10
|
+
<pre><span class="cmt"># File lib/web/testing.rb, line 350</span>
|
11
11
|
<span class="kw">def</span> assert_header key, value, msg=<span class="str">""</span>
|
12
12
|
Web.assert_header key, value, msg
|
13
13
|
<span class="kw">end</span></pre>
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<link rel=StyleSheet href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
8
8
|
</head>
|
9
9
|
<body bgcolor="white">
|
10
|
-
<pre><span class="cmt"># File lib/web/testing.rb, line
|
10
|
+
<pre><span class="cmt"># File lib/web/testing.rb, line 355</span>
|
11
11
|
<span class="kw">def</span> assert_cookie key, value, msg=<span class="str">""</span>
|
12
12
|
Web.assert_cookie key, value, msg
|
13
13
|
<span class="kw">end</span></pre>
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<link rel=StyleSheet href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
8
8
|
</head>
|
9
9
|
<body bgcolor="white">
|
10
|
-
<pre><span class="cmt"># File lib/web/testing.rb, line
|
10
|
+
<pre><span class="cmt"># File lib/web/testing.rb, line 361</span>
|
11
11
|
<span class="kw">def</span> assert_options( formname, expected={})
|
12
12
|
options = Web.get_formreader.get_options(formname)
|
13
13
|
expected.each{ |k,v|
|
data/doc/rdoc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Tue Nov 02 01:22:31 EST 2004
|
data/doc/rdoc/files/README.html
CHANGED
@@ -29,7 +29,7 @@
|
|
29
29
|
</tr>
|
30
30
|
<tr>
|
31
31
|
<td class="small-title-font">Modified:</td>
|
32
|
-
<td class="small-title-font">
|
32
|
+
<td class="small-title-font">Tue Nov 02 01:15:43 EST 2004</td>
|
33
33
|
</tr>
|
34
34
|
</table>
|
35
35
|
</td></tr></table></td>
|
@@ -124,7 +124,9 @@ for this:
|
|
124
124
|
<h3>Hello World</h3>
|
125
125
|
<pre>
|
126
126
|
require 'web'
|
127
|
-
Web
|
127
|
+
Web::process do
|
128
|
+
Web << 'Hello World'
|
129
|
+
end
|
128
130
|
</pre>
|
129
131
|
<h3>Testing an App</h3>
|
130
132
|
<p>
|
@@ -142,7 +144,9 @@ where script.rb is:
|
|
142
144
|
#!/usr/bin/ruby
|
143
145
|
require 'web'
|
144
146
|
|
145
|
-
Web
|
147
|
+
Web::process do
|
148
|
+
Web << "param is #{Web["param"]}"
|
149
|
+
end
|
146
150
|
</pre>
|
147
151
|
<p>
|
148
152
|
and test.rb is:
|
@@ -29,7 +29,7 @@
|
|
29
29
|
</tr>
|
30
30
|
<tr>
|
31
31
|
<td class="small-title-font">Modified:</td>
|
32
|
-
<td class="small-title-font">
|
32
|
+
<td class="small-title-font">Tue Nov 02 01:21:59 EST 2004</td>
|
33
33
|
</tr>
|
34
34
|
</table>
|
35
35
|
</td></tr></table></td>
|
@@ -60,14 +60,8 @@ run it with a shebang:
|
|
60
60
|
#!/usr/local/bin/narf
|
61
61
|
</pre>
|
62
62
|
<p>
|
63
|
-
This file may
|
64
|
-
|
65
|
-
</p>
|
66
|
-
<p>
|
67
|
-
Cheers,
|
68
|
-
</p>
|
69
|
-
<p>
|
70
|
-
patrick@hexane.org
|
63
|
+
This file may have a buffer overflow in it. Please be cautious with this
|
64
|
+
until I can get verification that it is ok.
|
71
65
|
</p>
|
72
66
|
</div>
|
73
67
|
|
@@ -29,7 +29,7 @@
|
|
29
29
|
</tr>
|
30
30
|
<tr>
|
31
31
|
<td class="small-title-font">Modified:</td>
|
32
|
-
<td class="small-title-font">
|
32
|
+
<td class="small-title-font">Tue Nov 02 01:20:38 EST 2004</td>
|
33
33
|
</tr>
|
34
34
|
</table>
|
35
35
|
</td></tr></table></td>
|
@@ -58,7 +58,7 @@ you will need to make sure that the cgi script executes in a Web::process
|
|
58
58
|
block:
|
59
59
|
</p>
|
60
60
|
<pre>
|
61
|
-
#!/usr/local/bin/ruby
|
61
|
+
#!/usr/local/bin/ruby -rweb
|
62
62
|
|
63
63
|
Web::process{
|
64
64
|
Web << 'Hello World!'
|
data/lib/web.rb
CHANGED
@@ -78,12 +78,15 @@ end
|
|
78
78
|
# Use the Web module to interact with the client. The module
|
79
79
|
# delegates to a Web::CGI object, which does the actual work.
|
80
80
|
#
|
81
|
-
# #!/usr/bin/
|
82
|
-
#
|
83
|
-
# Web
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
81
|
+
# #!/usr/bin/ruby
|
82
|
+
# require 'web'
|
83
|
+
# Web::process do
|
84
|
+
# Web["field"] # access parameters
|
85
|
+
# Web.cookies["muppet"] # access cookies
|
86
|
+
# Web.session["key"] ||= "value" # get and set session values
|
87
|
+
# Web.set_cookie( "muppet", "cookie monster" ) # set cookies
|
88
|
+
# Web.puts "something" # print 'something' out
|
89
|
+
# end
|
87
90
|
#
|
88
91
|
# If the request contained multipart/form-data, uploaded files are returned as
|
89
92
|
# Web::Upload objects. Other parameters are treated as strings.
|
@@ -176,18 +179,10 @@ module Web
|
|
176
179
|
end
|
177
180
|
end
|
178
181
|
|
179
|
-
#
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
{ /&/ => '&' }.each{ |char, entity|
|
184
|
-
newstring.gsub!( char, entity )
|
185
|
-
}
|
186
|
-
newstring
|
187
|
-
end
|
188
|
-
|
189
|
-
# Escape URL encode
|
190
|
-
# url_encoded_string = Web::escape("string")
|
182
|
+
# URL-encode a string.
|
183
|
+
# url_encoded_string = Web::escape("'Stop!' said Fred")
|
184
|
+
# # => "%27Stop%21%27+said+Fred"
|
185
|
+
# (from cgi.rb)
|
191
186
|
def Web::escape(string)
|
192
187
|
return nil unless string
|
193
188
|
string.gsub(/([^ a-zA-Z0-9_.-]+)/n) do
|
@@ -195,8 +190,11 @@ module Web
|
|
195
190
|
end.tr(' ', '+')
|
196
191
|
end
|
197
192
|
|
198
|
-
|
199
|
-
#
|
193
|
+
|
194
|
+
# URL-decode a string.
|
195
|
+
# string = Web::unescape("%27Stop%21%27+said+Fred")
|
196
|
+
# # => "'Stop!' said Fred"
|
197
|
+
# (from cgi.rb)
|
200
198
|
def Web::unescape(string)
|
201
199
|
return nil unless string
|
202
200
|
string.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n) do
|
@@ -204,6 +202,115 @@ module Web
|
|
204
202
|
end
|
205
203
|
end
|
206
204
|
|
205
|
+
|
206
|
+
# Escape special characters in HTML, namely &\"<>
|
207
|
+
# Web::escape_html('Usage: foo "bar" <baz>')
|
208
|
+
# # => "Usage: foo "bar" <baz>"
|
209
|
+
# (from cgi.rb)
|
210
|
+
def Web::escape_html(string)
|
211
|
+
return nil unless string
|
212
|
+
string.gsub(/&/n, '&').gsub(/\"/n, '"').gsub(/>/n, '>').gsub(/</n, '<')
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
# Unescape a string that has been HTML-escaped
|
217
|
+
# Web::unescape_html("Usage: foo "bar" <baz>")
|
218
|
+
# # => "Usage: foo \"bar\" <baz>"
|
219
|
+
# (from cgi.rb)
|
220
|
+
def Web::unescape_html(string)
|
221
|
+
return nil unless string
|
222
|
+
string.gsub(/&(.*?);/n) do
|
223
|
+
match = $1.dup
|
224
|
+
case match
|
225
|
+
when /\Aamp\z/ni then '&'
|
226
|
+
when /\Aquot\z/ni then '"'
|
227
|
+
when /\Agt\z/ni then '>'
|
228
|
+
when /\Alt\z/ni then '<'
|
229
|
+
when /\A#0*(\d+)\z/n then
|
230
|
+
if Integer($1) < 256
|
231
|
+
Integer($1).chr
|
232
|
+
else
|
233
|
+
if Integer($1) < 65536 and ($KCODE[0] == ?u or $KCODE[0] == ?U)
|
234
|
+
[Integer($1)].pack("U")
|
235
|
+
else
|
236
|
+
"&##{$1};"
|
237
|
+
end
|
238
|
+
end
|
239
|
+
when /\A#x([0-9a-f]+)\z/ni then
|
240
|
+
if $1.hex < 256
|
241
|
+
$1.hex.chr
|
242
|
+
else
|
243
|
+
if $1.hex < 65536 and ($KCODE[0] == ?u or $KCODE[0] == ?U)
|
244
|
+
[$1.hex].pack("U")
|
245
|
+
else
|
246
|
+
"&#x#{$1};"
|
247
|
+
end
|
248
|
+
end
|
249
|
+
else
|
250
|
+
"&#{match};"
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
|
256
|
+
# Escape only the tags of certain HTML elements in +string+.
|
257
|
+
#
|
258
|
+
# Takes an element or elements or array of elements. Each element
|
259
|
+
# is specified by the name of the element, without angle brackets.
|
260
|
+
# This matches both the start and the end tag of that element.
|
261
|
+
# The attribute list of the open tag will also be escaped (for
|
262
|
+
# instance, the double-quotes surrounding attribute values).
|
263
|
+
#
|
264
|
+
# print Web::escape_element('<BR><A HREF="url"></A>', "A", "IMG")
|
265
|
+
# # "<BR><A HREF="url"></A>"
|
266
|
+
#
|
267
|
+
# print Web::escape_element('<BR><A HREF="url"></A>', ["A", "IMG"])
|
268
|
+
# # "<BR><A HREF="url"></A>"
|
269
|
+
#
|
270
|
+
# (from cgi.rb)
|
271
|
+
def Web::escape_element(string, *elements)
|
272
|
+
return nil unless string
|
273
|
+
elements = elements[0] if elements[0].kind_of?(Array)
|
274
|
+
unless elements.empty?
|
275
|
+
string.gsub(/<\/?(?:#{elements.join("|")})(?!\w)(?:.|\n)*?>/ni) do
|
276
|
+
Web::escape_html($&)
|
277
|
+
end
|
278
|
+
else
|
279
|
+
string
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
|
284
|
+
# Undo escaping such as that done by Web::escape_element()
|
285
|
+
#
|
286
|
+
# print Web::unescape_element(
|
287
|
+
# Web::escapeHTML('<BR><A HREF="url"></A>'), "A", "IMG")
|
288
|
+
# # "<BR><A HREF="url"></A>"
|
289
|
+
#
|
290
|
+
# print Web::unescape_element(
|
291
|
+
# Web::escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"])
|
292
|
+
# # "<BR><A HREF="url"></A>"
|
293
|
+
# (from cgi.rb)
|
294
|
+
def Web::unescape_element(string, *elements)
|
295
|
+
return nil unless string
|
296
|
+
elements = elements[0] if elements[0].kind_of?(Array)
|
297
|
+
unless elements.empty?
|
298
|
+
string.gsub(/<\/?(?:#{elements.join("|")})(?!\w)(?:.|\n)*?>/ni) do
|
299
|
+
Web::unescape_html($&)
|
300
|
+
end
|
301
|
+
else
|
302
|
+
string
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
class << self
|
307
|
+
alias escapeHTML escape_html
|
308
|
+
alias html_encode escape_html
|
309
|
+
alias unescapeHTML unescape_html
|
310
|
+
alias escapeElement escape_element
|
311
|
+
alias unescapeElement unescape_element
|
312
|
+
end
|
313
|
+
|
207
314
|
RFC822_DAYS = %w[ Sun Mon Tue Wed Thu Fri Sat ]
|
208
315
|
RFC822_MONTHS = %w[ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ]
|
209
316
|
# Make RFC1123 date string
|
data/lib/web/parser.rb
CHANGED
@@ -189,20 +189,32 @@ module Web
|
|
189
189
|
raise EOFError, "no content body"
|
190
190
|
end
|
191
191
|
|
192
|
+
# ok... so what the hell does this do?
|
193
|
+
# I promise never to denigrate the accomplishments
|
194
|
+
# of my predecessors again :-)
|
195
|
+
# ~ pat
|
192
196
|
until -1 == content_length
|
193
197
|
head = nil
|
194
198
|
body = Tempfile.new("Web")
|
195
199
|
body.binmode
|
196
200
|
|
201
|
+
# until we have:
|
202
|
+
# * a header
|
203
|
+
# * and a buffer that has a boundary
|
204
|
+
# so far, make sense to me.
|
197
205
|
until head and /#{boundary}(?:#{EOL}|--)/n.match(buf)
|
198
|
-
|
206
|
+
# if we have a header....
|
199
207
|
if head
|
208
|
+
# !??!??!?!?!
|
200
209
|
trim_size = (EOL + boundary + EOL).size
|
201
210
|
if trim_size < buf.size
|
202
211
|
body.print buf[0 ... (buf.size - trim_size)]
|
203
212
|
buf[0 ... (buf.size - trim_size)] = ""
|
204
213
|
end
|
214
|
+
|
215
|
+
# If we have a double space (the smell of a header...)
|
205
216
|
elsif /#{EOL}#{EOL}/n.match(buf)
|
217
|
+
# extract the header, and erase it from the buffer
|
206
218
|
buf = buf.sub(/\A((?:.|\n)*?#{EOL})#{EOL}/n) do
|
207
219
|
head = $1.dup
|
208
220
|
""
|
@@ -210,18 +222,18 @@ module Web
|
|
210
222
|
next
|
211
223
|
end
|
212
224
|
|
225
|
+
# read a chunk from the input
|
213
226
|
c = if bufsize < content_length
|
214
227
|
input.read(bufsize) or ''
|
215
228
|
else
|
216
229
|
input.read(content_length) or ''
|
217
230
|
end
|
231
|
+
# add it to the input, reduce our countdown
|
218
232
|
buf.concat c
|
219
233
|
content_length -= c.size
|
220
|
-
|
221
234
|
end
|
222
235
|
|
223
|
-
|
224
|
-
/Content-Disposition:.* filename="?([^\";]*)"?/ni.match(head)
|
236
|
+
/Content-Disposition:.* filename="?([^\";]*)"?/ni.match(head)
|
225
237
|
filename = ($1 or "").dup
|
226
238
|
if /Mac/ni.match(env['http_user_agent']) and
|
227
239
|
/Mozilla/ni.match(env['http_user_agent']) and
|
@@ -232,7 +244,9 @@ module Web
|
|
232
244
|
/Content-Type: (.*)/ni.match(head)
|
233
245
|
content_type = ($1 or "").strip
|
234
246
|
|
235
|
-
|
247
|
+
# is this the part that is eating too much?
|
248
|
+
#buf = buf.sub(/\A(.*?)(?:#{EOL})?#{boundary}(#{EOL}|--)/mn) do
|
249
|
+
buf = buf.sub(/\A((?:.|\n)*?)(?:[\r\n]{1,2})?#{boundary}([\r\n]{1,2}|--)/n) do
|
236
250
|
body.print $1
|
237
251
|
if "--" == $2
|
238
252
|
content_length = -1
|
@@ -241,7 +255,8 @@ module Web
|
|
241
255
|
end
|
242
256
|
|
243
257
|
body.rewind
|
244
|
-
|
258
|
+
|
259
|
+
|
245
260
|
if (content_type.empty?)
|
246
261
|
upload = body.read
|
247
262
|
else
|
@@ -250,7 +265,10 @@ module Web
|
|
250
265
|
|
251
266
|
/Content-Disposition:.* name="?([^\";]*)"?/ni.match(head)
|
252
267
|
name = $1.dup
|
253
|
-
|
268
|
+
|
269
|
+
|
270
|
+
body.rewind
|
271
|
+
|
254
272
|
if params.has_key?(name)
|
255
273
|
params[name].push(upload)
|
256
274
|
else
|