rack 1.1.6 → 1.6.9
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.
- checksums.yaml +7 -0
- data/COPYING +1 -1
- data/HISTORY.md +375 -0
- data/KNOWN-ISSUES +23 -0
- data/README.rdoc +312 -0
- data/Rakefile +124 -0
- data/SPEC +125 -32
- data/contrib/rack.png +0 -0
- data/contrib/rack.svg +150 -0
- data/contrib/rack_logo.svg +1 -1
- data/contrib/rdoc.css +412 -0
- data/example/protectedlobster.rb +1 -1
- data/lib/rack/auth/abstract/handler.rb +4 -4
- data/lib/rack/auth/abstract/request.rb +7 -5
- data/lib/rack/auth/basic.rb +1 -1
- data/lib/rack/auth/digest/md5.rb +7 -3
- data/lib/rack/auth/digest/nonce.rb +1 -1
- data/lib/rack/auth/digest/params.rb +7 -9
- data/lib/rack/auth/digest/request.rb +10 -9
- data/lib/rack/backports/uri/common_18.rb +56 -0
- data/lib/rack/backports/uri/common_192.rb +52 -0
- data/lib/rack/backports/uri/common_193.rb +29 -0
- data/lib/rack/body_proxy.rb +39 -0
- data/lib/rack/builder.rb +106 -22
- data/lib/rack/cascade.rb +17 -6
- data/lib/rack/chunked.rb +44 -24
- data/lib/rack/commonlogger.rb +36 -13
- data/lib/rack/conditionalget.rb +49 -17
- data/lib/rack/config.rb +5 -0
- data/lib/rack/content_length.rb +14 -6
- data/lib/rack/content_type.rb +7 -1
- data/lib/rack/deflater.rb +73 -15
- data/lib/rack/directory.rb +18 -8
- data/lib/rack/etag.rb +59 -9
- data/lib/rack/file.rb +106 -44
- data/lib/rack/handler/cgi.rb +11 -11
- data/lib/rack/handler/fastcgi.rb +18 -6
- data/lib/rack/handler/lsws.rb +2 -4
- data/lib/rack/handler/mongrel.rb +22 -6
- data/lib/rack/handler/scgi.rb +16 -8
- data/lib/rack/handler/thin.rb +19 -4
- data/lib/rack/handler/webrick.rb +72 -19
- data/lib/rack/handler.rb +47 -14
- data/lib/rack/head.rb +10 -2
- data/lib/rack/lint.rb +260 -75
- data/lib/rack/lobster.rb +13 -8
- data/lib/rack/lock.rb +13 -3
- data/lib/rack/logger.rb +0 -2
- data/lib/rack/methodoverride.rb +27 -8
- data/lib/rack/mime.rb +625 -167
- data/lib/rack/mock.rb +78 -53
- data/lib/rack/multipart/generator.rb +93 -0
- data/lib/rack/multipart/parser.rb +253 -0
- data/lib/rack/multipart/uploaded_file.rb +34 -0
- data/lib/rack/multipart.rb +34 -0
- data/lib/rack/nulllogger.rb +21 -2
- data/lib/rack/recursive.rb +10 -5
- data/lib/rack/reloader.rb +3 -2
- data/lib/rack/request.rb +201 -74
- data/lib/rack/response.rb +41 -28
- data/lib/rack/rewindable_input.rb +15 -11
- data/lib/rack/runtime.rb +16 -3
- data/lib/rack/sendfile.rb +47 -29
- data/lib/rack/server.rb +223 -47
- data/lib/rack/session/abstract/id.rb +289 -30
- data/lib/rack/session/cookie.rb +133 -44
- data/lib/rack/session/memcache.rb +30 -56
- data/lib/rack/session/pool.rb +19 -43
- data/lib/rack/showexceptions.rb +53 -15
- data/lib/rack/showstatus.rb +14 -7
- data/lib/rack/static.rb +124 -12
- data/lib/rack/tempfile_reaper.rb +22 -0
- data/lib/rack/urlmap.rb +49 -15
- data/lib/rack/utils/okjson.rb +600 -0
- data/lib/rack/utils.rb +363 -361
- data/lib/rack.rb +17 -23
- data/rack.gemspec +11 -20
- data/test/builder/anything.rb +5 -0
- data/test/builder/comment.ru +4 -0
- data/test/builder/end.ru +5 -0
- data/test/builder/line.ru +1 -0
- data/test/builder/options.ru +2 -0
- data/test/cgi/assets/folder/test.js +1 -0
- data/test/cgi/assets/fonts/font.eot +1 -0
- data/test/cgi/assets/images/image.png +1 -0
- data/test/cgi/assets/index.html +1 -0
- data/test/cgi/assets/javascripts/app.js +1 -0
- data/test/cgi/assets/stylesheets/app.css +1 -0
- data/test/cgi/lighttpd.conf +26 -0
- data/test/cgi/rackup_stub.rb +6 -0
- data/test/cgi/sample_rackup.ru +5 -0
- data/test/cgi/test +9 -0
- data/test/cgi/test+directory/test+file +1 -0
- data/test/cgi/test.fcgi +8 -0
- data/test/cgi/test.ru +5 -0
- data/test/gemloader.rb +10 -0
- data/test/multipart/bad_robots +259 -0
- data/test/multipart/binary +0 -0
- data/test/multipart/content_type_and_no_filename +6 -0
- data/test/multipart/empty +10 -0
- data/test/multipart/fail_16384_nofile +814 -0
- data/test/multipart/file1.txt +1 -0
- data/test/multipart/filename_and_modification_param +7 -0
- data/test/multipart/filename_and_no_name +6 -0
- data/test/multipart/filename_with_escaped_quotes +6 -0
- data/test/multipart/filename_with_escaped_quotes_and_modification_param +7 -0
- data/test/multipart/filename_with_null_byte +7 -0
- data/test/multipart/filename_with_percent_escaped_quotes +6 -0
- data/test/multipart/filename_with_unescaped_percentages +6 -0
- data/test/multipart/filename_with_unescaped_percentages2 +6 -0
- data/test/multipart/filename_with_unescaped_percentages3 +6 -0
- data/test/multipart/filename_with_unescaped_quotes +6 -0
- data/test/multipart/ie +6 -0
- data/test/multipart/invalid_character +6 -0
- data/test/multipart/mixed_files +21 -0
- data/test/multipart/nested +10 -0
- data/test/multipart/none +9 -0
- data/test/multipart/semicolon +6 -0
- data/test/multipart/text +15 -0
- data/test/multipart/three_files_three_fields +31 -0
- data/test/multipart/webkit +32 -0
- data/test/rackup/config.ru +31 -0
- data/test/registering_handler/rack/handler/registering_myself.rb +8 -0
- data/test/{spec_rack_auth_basic.rb → spec_auth_basic.rb} +23 -15
- data/test/{spec_rack_auth_digest.rb → spec_auth_digest.rb} +56 -29
- data/test/spec_body_proxy.rb +85 -0
- data/test/spec_builder.rb +223 -0
- data/test/{spec_rack_cascade.rb → spec_cascade.rb} +28 -15
- data/test/{spec_rack_cgi.rb → spec_cgi.rb} +44 -31
- data/test/spec_chunked.rb +101 -0
- data/test/spec_commonlogger.rb +93 -0
- data/test/spec_conditionalget.rb +102 -0
- data/test/{spec_rack_config.rb → spec_config.rb} +6 -8
- data/test/spec_content_length.rb +85 -0
- data/test/spec_content_type.rb +45 -0
- data/test/spec_deflater.rb +339 -0
- data/test/{spec_rack_directory.rb → spec_directory.rb} +37 -10
- data/test/spec_etag.rb +107 -0
- data/test/{spec_rack_fastcgi.rb → spec_fastcgi.rb} +47 -29
- data/test/spec_file.rb +221 -0
- data/test/spec_handler.rb +72 -0
- data/test/spec_head.rb +45 -0
- data/test/{spec_rack_lint.rb → spec_lint.rb} +82 -60
- data/test/spec_lobster.rb +58 -0
- data/test/spec_lock.rb +164 -0
- data/test/spec_logger.rb +23 -0
- data/test/spec_methodoverride.rb +95 -0
- data/test/spec_mime.rb +51 -0
- data/test/{spec_rack_mock.rb → spec_mock.rb} +92 -38
- data/test/{spec_rack_mongrel.rb → spec_mongrel.rb} +46 -53
- data/test/spec_multipart.rb +600 -0
- data/test/spec_nulllogger.rb +20 -0
- data/test/spec_recursive.rb +72 -0
- data/test/spec_request.rb +1227 -0
- data/test/spec_response.rb +407 -0
- data/test/spec_rewindable_input.rb +118 -0
- data/test/spec_runtime.rb +49 -0
- data/test/spec_sendfile.rb +130 -0
- data/test/spec_server.rb +167 -0
- data/test/spec_session_abstract_id.rb +53 -0
- data/test/spec_session_cookie.rb +410 -0
- data/test/{spec_rack_session_memcache.rb → spec_session_memcache.rb} +119 -71
- data/test/{spec_rack_session_pool.rb → spec_session_pool.rb} +106 -69
- data/test/spec_showexceptions.rb +85 -0
- data/test/spec_showstatus.rb +103 -0
- data/test/spec_static.rb +145 -0
- data/test/spec_tempfile_reaper.rb +63 -0
- data/test/{spec_rack_thin.rb → spec_thin.rb} +35 -35
- data/test/{spec_rack_urlmap.rb → spec_urlmap.rb} +40 -19
- data/test/spec_utils.rb +647 -0
- data/test/spec_version.rb +17 -0
- data/test/spec_webrick.rb +184 -0
- data/test/static/another/index.html +1 -0
- data/test/static/index.html +1 -0
- data/test/testrequest.rb +78 -0
- data/test/unregistered_handler/rack/handler/unregistered.rb +7 -0
- data/test/unregistered_handler/rack/handler/unregistered_long_one.rb +7 -0
- metadata +220 -239
- data/RDOX +0 -0
- data/README +0 -592
- data/lib/rack/adapter/camping.rb +0 -22
- data/test/spec_auth.rb +0 -57
- data/test/spec_rack_builder.rb +0 -84
- data/test/spec_rack_camping.rb +0 -55
- data/test/spec_rack_chunked.rb +0 -62
- data/test/spec_rack_commonlogger.rb +0 -61
- data/test/spec_rack_conditionalget.rb +0 -41
- data/test/spec_rack_content_length.rb +0 -43
- data/test/spec_rack_content_type.rb +0 -30
- data/test/spec_rack_deflater.rb +0 -127
- data/test/spec_rack_etag.rb +0 -17
- data/test/spec_rack_file.rb +0 -75
- data/test/spec_rack_handler.rb +0 -43
- data/test/spec_rack_head.rb +0 -30
- data/test/spec_rack_lobster.rb +0 -45
- data/test/spec_rack_lock.rb +0 -38
- data/test/spec_rack_logger.rb +0 -21
- data/test/spec_rack_methodoverride.rb +0 -60
- data/test/spec_rack_nulllogger.rb +0 -13
- data/test/spec_rack_recursive.rb +0 -77
- data/test/spec_rack_request.rb +0 -594
- data/test/spec_rack_response.rb +0 -221
- data/test/spec_rack_rewindable_input.rb +0 -118
- data/test/spec_rack_runtime.rb +0 -35
- data/test/spec_rack_sendfile.rb +0 -86
- data/test/spec_rack_session_cookie.rb +0 -92
- data/test/spec_rack_showexceptions.rb +0 -21
- data/test/spec_rack_showstatus.rb +0 -72
- data/test/spec_rack_static.rb +0 -37
- data/test/spec_rack_utils.rb +0 -557
- data/test/spec_rack_webrick.rb +0 -130
- data/test/spec_rackup.rb +0 -164
data/test/spec_rack_response.rb
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
require 'test/spec'
|
|
2
|
-
require 'set'
|
|
3
|
-
|
|
4
|
-
require 'rack/response'
|
|
5
|
-
|
|
6
|
-
context "Rack::Response" do
|
|
7
|
-
specify "has sensible default values" do
|
|
8
|
-
response = Rack::Response.new
|
|
9
|
-
status, header, body = response.finish
|
|
10
|
-
status.should.equal 200
|
|
11
|
-
header.should.equal "Content-Type" => "text/html"
|
|
12
|
-
body.each { |part|
|
|
13
|
-
part.should.equal ""
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
response = Rack::Response.new
|
|
17
|
-
status, header, body = *response
|
|
18
|
-
status.should.equal 200
|
|
19
|
-
header.should.equal "Content-Type" => "text/html"
|
|
20
|
-
body.each { |part|
|
|
21
|
-
part.should.equal ""
|
|
22
|
-
}
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
specify "can be written to" do
|
|
26
|
-
response = Rack::Response.new
|
|
27
|
-
|
|
28
|
-
status, header, body = response.finish do
|
|
29
|
-
response.write "foo"
|
|
30
|
-
response.write "bar"
|
|
31
|
-
response.write "baz"
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
parts = []
|
|
35
|
-
body.each { |part| parts << part }
|
|
36
|
-
|
|
37
|
-
parts.should.equal ["foo", "bar", "baz"]
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
specify "can set and read headers" do
|
|
41
|
-
response = Rack::Response.new
|
|
42
|
-
response["Content-Type"].should.equal "text/html"
|
|
43
|
-
response["Content-Type"] = "text/plain"
|
|
44
|
-
response["Content-Type"].should.equal "text/plain"
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
specify "can set cookies" do
|
|
48
|
-
response = Rack::Response.new
|
|
49
|
-
|
|
50
|
-
response.set_cookie "foo", "bar"
|
|
51
|
-
response["Set-Cookie"].should.equal "foo=bar"
|
|
52
|
-
response.set_cookie "foo2", "bar2"
|
|
53
|
-
response["Set-Cookie"].should.equal ["foo=bar", "foo2=bar2"].join("\n")
|
|
54
|
-
response.set_cookie "foo3", "bar3"
|
|
55
|
-
response["Set-Cookie"].should.equal ["foo=bar", "foo2=bar2", "foo3=bar3"].join("\n")
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
specify "formats the Cookie expiration date accordingly to RFC 2109" do
|
|
59
|
-
response = Rack::Response.new
|
|
60
|
-
|
|
61
|
-
response.set_cookie "foo", {:value => "bar", :expires => Time.now+10}
|
|
62
|
-
response["Set-Cookie"].should.match(
|
|
63
|
-
/expires=..., \d\d-...-\d\d\d\d \d\d:\d\d:\d\d .../)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
specify "can set secure cookies" do
|
|
67
|
-
response = Rack::Response.new
|
|
68
|
-
response.set_cookie "foo", {:value => "bar", :secure => true}
|
|
69
|
-
response["Set-Cookie"].should.equal "foo=bar; secure"
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
specify "can set http only cookies" do
|
|
73
|
-
response = Rack::Response.new
|
|
74
|
-
response.set_cookie "foo", {:value => "bar", :httponly => true}
|
|
75
|
-
response["Set-Cookie"].should.equal "foo=bar; HttpOnly"
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
specify "can delete cookies" do
|
|
79
|
-
response = Rack::Response.new
|
|
80
|
-
response.set_cookie "foo", "bar"
|
|
81
|
-
response.set_cookie "foo2", "bar2"
|
|
82
|
-
response.delete_cookie "foo"
|
|
83
|
-
response["Set-Cookie"].should.equal ["foo2=bar2",
|
|
84
|
-
"foo=; expires=Thu, 01-Jan-1970 00:00:00 GMT"].join("\n")
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
specify "can do redirects" do
|
|
88
|
-
response = Rack::Response.new
|
|
89
|
-
response.redirect "/foo"
|
|
90
|
-
status, header, body = response.finish
|
|
91
|
-
|
|
92
|
-
status.should.equal 302
|
|
93
|
-
header["Location"].should.equal "/foo"
|
|
94
|
-
|
|
95
|
-
response = Rack::Response.new
|
|
96
|
-
response.redirect "/foo", 307
|
|
97
|
-
status, header, body = response.finish
|
|
98
|
-
|
|
99
|
-
status.should.equal 307
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
specify "has a useful constructor" do
|
|
103
|
-
r = Rack::Response.new("foo")
|
|
104
|
-
status, header, body = r.finish
|
|
105
|
-
str = ""; body.each { |part| str << part }
|
|
106
|
-
str.should.equal "foo"
|
|
107
|
-
|
|
108
|
-
r = Rack::Response.new(["foo", "bar"])
|
|
109
|
-
status, header, body = r.finish
|
|
110
|
-
str = ""; body.each { |part| str << part }
|
|
111
|
-
str.should.equal "foobar"
|
|
112
|
-
|
|
113
|
-
r = Rack::Response.new(["foo", "bar"].to_set)
|
|
114
|
-
r.write "foo"
|
|
115
|
-
status, header, body = r.finish
|
|
116
|
-
str = ""; body.each { |part| str << part }
|
|
117
|
-
str.should.equal "foobarfoo"
|
|
118
|
-
|
|
119
|
-
r = Rack::Response.new([], 500)
|
|
120
|
-
r.status.should.equal 500
|
|
121
|
-
|
|
122
|
-
r = Rack::Response.new([], "200 OK")
|
|
123
|
-
r.status.should.equal 200
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
specify "has a constructor that can take a block" do
|
|
127
|
-
r = Rack::Response.new { |res|
|
|
128
|
-
res.status = 404
|
|
129
|
-
res.write "foo"
|
|
130
|
-
}
|
|
131
|
-
status, header, body = r.finish
|
|
132
|
-
str = ""; body.each { |part| str << part }
|
|
133
|
-
str.should.equal "foo"
|
|
134
|
-
status.should.equal 404
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
specify "doesn't return invalid responses" do
|
|
138
|
-
r = Rack::Response.new(["foo", "bar"], 204)
|
|
139
|
-
status, header, body = r.finish
|
|
140
|
-
str = ""; body.each { |part| str << part }
|
|
141
|
-
str.should.be.empty
|
|
142
|
-
header["Content-Type"].should.equal nil
|
|
143
|
-
|
|
144
|
-
lambda {
|
|
145
|
-
Rack::Response.new(Object.new)
|
|
146
|
-
}.should.raise(TypeError).
|
|
147
|
-
message.should =~ /stringable or iterable required/
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
specify "knows if it's empty" do
|
|
151
|
-
r = Rack::Response.new
|
|
152
|
-
r.should.be.empty
|
|
153
|
-
r.write "foo"
|
|
154
|
-
r.should.not.be.empty
|
|
155
|
-
|
|
156
|
-
r = Rack::Response.new
|
|
157
|
-
r.should.be.empty
|
|
158
|
-
r.finish
|
|
159
|
-
r.should.be.empty
|
|
160
|
-
|
|
161
|
-
r = Rack::Response.new
|
|
162
|
-
r.should.be.empty
|
|
163
|
-
r.finish { }
|
|
164
|
-
r.should.not.be.empty
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
specify "should provide access to the HTTP status" do
|
|
168
|
-
res = Rack::Response.new
|
|
169
|
-
res.status = 200
|
|
170
|
-
res.should.be.successful
|
|
171
|
-
res.should.be.ok
|
|
172
|
-
|
|
173
|
-
res.status = 404
|
|
174
|
-
res.should.not.be.successful
|
|
175
|
-
res.should.be.client_error
|
|
176
|
-
res.should.be.not_found
|
|
177
|
-
|
|
178
|
-
res.status = 501
|
|
179
|
-
res.should.not.be.successful
|
|
180
|
-
res.should.be.server_error
|
|
181
|
-
|
|
182
|
-
res.status = 307
|
|
183
|
-
res.should.be.redirect
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
specify "should provide access to the HTTP headers" do
|
|
187
|
-
res = Rack::Response.new
|
|
188
|
-
res["Content-Type"] = "text/yaml"
|
|
189
|
-
|
|
190
|
-
res.should.include "Content-Type"
|
|
191
|
-
res.headers["Content-Type"].should.equal "text/yaml"
|
|
192
|
-
res["Content-Type"].should.equal "text/yaml"
|
|
193
|
-
res.content_type.should.equal "text/yaml"
|
|
194
|
-
res.content_length.should.be.nil
|
|
195
|
-
res.location.should.be.nil
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
specify "does not add or change Content-Length when #finish()ing" do
|
|
199
|
-
res = Rack::Response.new
|
|
200
|
-
res.status = 200
|
|
201
|
-
res.finish
|
|
202
|
-
res.headers["Content-Length"].should.be.nil
|
|
203
|
-
|
|
204
|
-
res = Rack::Response.new
|
|
205
|
-
res.status = 200
|
|
206
|
-
res.headers["Content-Length"] = "10"
|
|
207
|
-
res.finish
|
|
208
|
-
res.headers["Content-Length"].should.equal "10"
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
specify "updates Content-Length when body appended to using #write" do
|
|
212
|
-
res = Rack::Response.new
|
|
213
|
-
res.status = 200
|
|
214
|
-
res.headers["Content-Length"].should.be.nil
|
|
215
|
-
res.write "Hi"
|
|
216
|
-
res.headers["Content-Length"].should.equal "2"
|
|
217
|
-
res.write " there"
|
|
218
|
-
res.headers["Content-Length"].should.equal "8"
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
end
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
require 'test/spec'
|
|
2
|
-
require 'stringio'
|
|
3
|
-
require 'rack/rewindable_input'
|
|
4
|
-
|
|
5
|
-
shared_context "a rewindable IO object" do
|
|
6
|
-
setup do
|
|
7
|
-
@rio = Rack::RewindableInput.new(@io)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
teardown do
|
|
11
|
-
@rio.close
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
specify "should be able to handle to read()" do
|
|
15
|
-
@rio.read.should.equal "hello world"
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
specify "should be able to handle to read(nil)" do
|
|
19
|
-
@rio.read(nil).should.equal "hello world"
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
specify "should be able to handle to read(length)" do
|
|
23
|
-
@rio.read(1).should.equal "h"
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
specify "should be able to handle to read(length, buffer)" do
|
|
27
|
-
buffer = ""
|
|
28
|
-
result = @rio.read(1, buffer)
|
|
29
|
-
result.should.equal "h"
|
|
30
|
-
result.object_id.should.equal buffer.object_id
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
specify "should be able to handle to read(nil, buffer)" do
|
|
34
|
-
buffer = ""
|
|
35
|
-
result = @rio.read(nil, buffer)
|
|
36
|
-
result.should.equal "hello world"
|
|
37
|
-
result.object_id.should.equal buffer.object_id
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
specify "should rewind to the beginning when #rewind is called" do
|
|
41
|
-
@rio.read(1)
|
|
42
|
-
@rio.rewind
|
|
43
|
-
@rio.read.should.equal "hello world"
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
specify "should be able to handle gets" do
|
|
47
|
-
@rio.gets.should == "hello world"
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
specify "should be able to handle each" do
|
|
51
|
-
array = []
|
|
52
|
-
@rio.each do |data|
|
|
53
|
-
array << data
|
|
54
|
-
end
|
|
55
|
-
array.should.equal(["hello world"])
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
specify "should not buffer into a Tempfile if no data has been read yet" do
|
|
59
|
-
@rio.instance_variable_get(:@rewindable_io).should.be.nil
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
specify "should buffer into a Tempfile when data has been consumed for the first time" do
|
|
63
|
-
@rio.read(1)
|
|
64
|
-
tempfile = @rio.instance_variable_get(:@rewindable_io)
|
|
65
|
-
tempfile.should.not.be.nil
|
|
66
|
-
@rio.read(1)
|
|
67
|
-
tempfile2 = @rio.instance_variable_get(:@rewindable_io)
|
|
68
|
-
tempfile2.should.equal tempfile
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
specify "should close the underlying tempfile upon calling #close" do
|
|
72
|
-
@rio.read(1)
|
|
73
|
-
tempfile = @rio.instance_variable_get(:@rewindable_io)
|
|
74
|
-
@rio.close
|
|
75
|
-
tempfile.should.be.closed
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
specify "should be possibel to call #close when no data has been buffered yet" do
|
|
79
|
-
@rio.close
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
specify "should be possible to call #close multiple times" do
|
|
83
|
-
@rio.close
|
|
84
|
-
@rio.close
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
context "Rack::RewindableInput" do
|
|
89
|
-
context "given an IO object that is already rewindable" do
|
|
90
|
-
setup do
|
|
91
|
-
@io = StringIO.new("hello world")
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
it_should_behave_like "a rewindable IO object"
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
context "given an IO object that is not rewindable" do
|
|
98
|
-
setup do
|
|
99
|
-
@io = StringIO.new("hello world")
|
|
100
|
-
@io.instance_eval do
|
|
101
|
-
undef :rewind
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
it_should_behave_like "a rewindable IO object"
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
context "given an IO object whose rewind method raises Errno::ESPIPE" do
|
|
109
|
-
setup do
|
|
110
|
-
@io = StringIO.new("hello world")
|
|
111
|
-
def @io.rewind
|
|
112
|
-
raise Errno::ESPIPE, "You can't rewind this!"
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
it_should_behave_like "a rewindable IO object"
|
|
117
|
-
end
|
|
118
|
-
end
|
data/test/spec_rack_runtime.rb
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
require 'test/spec'
|
|
2
|
-
require 'rack/mock'
|
|
3
|
-
require 'rack/runtime'
|
|
4
|
-
|
|
5
|
-
context "Rack::Runtime" do
|
|
6
|
-
specify "sets X-Runtime is none is set" do
|
|
7
|
-
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] }
|
|
8
|
-
response = Rack::Runtime.new(app).call({})
|
|
9
|
-
response[1]['X-Runtime'].should =~ /[\d\.]+/
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
specify "does not set the X-Runtime if it is already set" do
|
|
13
|
-
app = lambda { |env| [200, {'Content-Type' => 'text/plain', "X-Runtime" => "foobar"}, "Hello, World!"] }
|
|
14
|
-
response = Rack::Runtime.new(app).call({})
|
|
15
|
-
response[1]['X-Runtime'].should == "foobar"
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
specify "should allow a suffix to be set" do
|
|
19
|
-
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] }
|
|
20
|
-
response = Rack::Runtime.new(app, "Test").call({})
|
|
21
|
-
response[1]['X-Runtime-Test'].should =~ /[\d\.]+/
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
specify "should allow multiple timers to be set" do
|
|
25
|
-
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] }
|
|
26
|
-
runtime1 = Rack::Runtime.new(app, "App")
|
|
27
|
-
runtime2 = Rack::Runtime.new(runtime1, "All")
|
|
28
|
-
response = runtime2.call({})
|
|
29
|
-
|
|
30
|
-
response[1]['X-Runtime-App'].should =~ /[\d\.]+/
|
|
31
|
-
response[1]['X-Runtime-All'].should =~ /[\d\.]+/
|
|
32
|
-
|
|
33
|
-
Float(response[1]['X-Runtime-All']).should > Float(response[1]['X-Runtime-App'])
|
|
34
|
-
end
|
|
35
|
-
end
|
data/test/spec_rack_sendfile.rb
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
require 'test/spec'
|
|
2
|
-
require 'rack/mock'
|
|
3
|
-
require 'rack/sendfile'
|
|
4
|
-
|
|
5
|
-
context "Rack::File" do
|
|
6
|
-
specify "should respond to #to_path" do
|
|
7
|
-
Rack::File.new(Dir.pwd).should.respond_to :to_path
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
context "Rack::Sendfile" do
|
|
12
|
-
def sendfile_body
|
|
13
|
-
res = ['Hello World']
|
|
14
|
-
def res.to_path ; "/tmp/hello.txt" ; end
|
|
15
|
-
res
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def simple_app(body=sendfile_body)
|
|
19
|
-
lambda { |env| [200, {'Content-Type' => 'text/plain'}, body] }
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def sendfile_app(body=sendfile_body)
|
|
23
|
-
Rack::Sendfile.new(simple_app(body))
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
setup do
|
|
27
|
-
@request = Rack::MockRequest.new(sendfile_app)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def request(headers={})
|
|
31
|
-
yield @request.get('/', headers)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
specify "does nothing when no X-Sendfile-Type header present" do
|
|
35
|
-
request do |response|
|
|
36
|
-
response.should.be.ok
|
|
37
|
-
response.body.should.equal 'Hello World'
|
|
38
|
-
response.headers.should.not.include 'X-Sendfile'
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
specify "sets X-Sendfile response header and discards body" do
|
|
43
|
-
request 'HTTP_X_SENDFILE_TYPE' => 'X-Sendfile' do |response|
|
|
44
|
-
response.should.be.ok
|
|
45
|
-
response.body.should.be.empty
|
|
46
|
-
response.headers['X-Sendfile'].should.equal '/tmp/hello.txt'
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
specify "sets X-Lighttpd-Send-File response header and discards body" do
|
|
51
|
-
request 'HTTP_X_SENDFILE_TYPE' => 'X-Lighttpd-Send-File' do |response|
|
|
52
|
-
response.should.be.ok
|
|
53
|
-
response.body.should.be.empty
|
|
54
|
-
response.headers['X-Lighttpd-Send-File'].should.equal '/tmp/hello.txt'
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
specify "sets X-Accel-Redirect response header and discards body" do
|
|
59
|
-
headers = {
|
|
60
|
-
'HTTP_X_SENDFILE_TYPE' => 'X-Accel-Redirect',
|
|
61
|
-
'HTTP_X_ACCEL_MAPPING' => '/tmp/=/foo/bar/'
|
|
62
|
-
}
|
|
63
|
-
request headers do |response|
|
|
64
|
-
response.should.be.ok
|
|
65
|
-
response.body.should.be.empty
|
|
66
|
-
response.headers['X-Accel-Redirect'].should.equal '/foo/bar/hello.txt'
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
specify 'writes to rack.error when no X-Accel-Mapping is specified' do
|
|
71
|
-
request 'HTTP_X_SENDFILE_TYPE' => 'X-Accel-Redirect' do |response|
|
|
72
|
-
response.should.be.ok
|
|
73
|
-
response.body.should.equal 'Hello World'
|
|
74
|
-
response.headers.should.not.include 'X-Accel-Redirect'
|
|
75
|
-
response.errors.should.include 'X-Accel-Mapping'
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
specify 'does nothing when body does not respond to #to_path' do
|
|
80
|
-
@request = Rack::MockRequest.new(sendfile_app(['Not a file...']))
|
|
81
|
-
request 'HTTP_X_SENDFILE_TYPE' => 'X-Sendfile' do |response|
|
|
82
|
-
response.body.should.equal 'Not a file...'
|
|
83
|
-
response.headers.should.not.include 'X-Sendfile'
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
require 'test/spec'
|
|
2
|
-
|
|
3
|
-
require 'rack/session/cookie'
|
|
4
|
-
require 'rack/mock'
|
|
5
|
-
require 'rack/response'
|
|
6
|
-
|
|
7
|
-
context "Rack::Session::Cookie" do
|
|
8
|
-
incrementor = lambda { |env|
|
|
9
|
-
env["rack.session"]["counter"] ||= 0
|
|
10
|
-
env["rack.session"]["counter"] += 1
|
|
11
|
-
Rack::Response.new(env["rack.session"].inspect).to_a
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
before do
|
|
15
|
-
@warnings = warnings = []
|
|
16
|
-
Rack::Session::Cookie.class_eval do
|
|
17
|
-
define_method(:warn) { |m| warnings << m }
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
after do
|
|
22
|
-
Rack::Session::Cookie.class_eval { remove_method :warn }
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
specify "warns if no secret is given" do
|
|
26
|
-
cookie = Rack::Session::Cookie.new(incrementor)
|
|
27
|
-
@warnings.first.should =~ /no secret/i
|
|
28
|
-
@warnings.clear
|
|
29
|
-
cookie = Rack::Session::Cookie.new(incrementor, :secret => 'abc')
|
|
30
|
-
@warnings.should.be.empty?
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
specify "creates a new cookie" do
|
|
34
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).get("/")
|
|
35
|
-
res["Set-Cookie"].should.match("rack.session=")
|
|
36
|
-
res.body.should.equal '{"counter"=>1}'
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
specify "loads from a cookie" do
|
|
40
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).get("/")
|
|
41
|
-
cookie = res["Set-Cookie"]
|
|
42
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).
|
|
43
|
-
get("/", "HTTP_COOKIE" => cookie)
|
|
44
|
-
res.body.should.equal '{"counter"=>2}'
|
|
45
|
-
cookie = res["Set-Cookie"]
|
|
46
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).
|
|
47
|
-
get("/", "HTTP_COOKIE" => cookie)
|
|
48
|
-
res.body.should.equal '{"counter"=>3}'
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
specify "survives broken cookies" do
|
|
52
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor)).
|
|
53
|
-
get("/", "HTTP_COOKIE" => "rack.session=blarghfasel")
|
|
54
|
-
res.body.should.equal '{"counter"=>1}'
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
bigcookie = lambda { |env|
|
|
58
|
-
env["rack.session"]["cookie"] = "big" * 3000
|
|
59
|
-
Rack::Response.new(env["rack.session"].inspect).to_a
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
specify "barks on too big cookies" do
|
|
63
|
-
lambda {
|
|
64
|
-
Rack::MockRequest.new(Rack::Session::Cookie.new(bigcookie)).
|
|
65
|
-
get("/", :fatal => true)
|
|
66
|
-
}.should.raise(Rack::MockRequest::FatalWarning)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
specify "loads from a cookie wih integrity hash" do
|
|
70
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor, :secret => 'test')).get("/")
|
|
71
|
-
cookie = res["Set-Cookie"]
|
|
72
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor, :secret => 'test')).
|
|
73
|
-
get("/", "HTTP_COOKIE" => cookie)
|
|
74
|
-
res.body.should.equal '{"counter"=>2}'
|
|
75
|
-
cookie = res["Set-Cookie"]
|
|
76
|
-
res = Rack::MockRequest.new(Rack::Session::Cookie.new(incrementor, :secret => 'test')).
|
|
77
|
-
get("/", "HTTP_COOKIE" => cookie)
|
|
78
|
-
res.body.should.equal '{"counter"=>3}'
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
specify "ignores tampered with session cookies" do
|
|
82
|
-
app = Rack::Session::Cookie.new(incrementor, :secret => 'test')
|
|
83
|
-
response1 = Rack::MockRequest.new(app).get("/")
|
|
84
|
-
_, digest = response1["Set-Cookie"].split("--")
|
|
85
|
-
tampered_with_cookie = "hackerman-was-here" + "--" + digest
|
|
86
|
-
response2 = Rack::MockRequest.new(app).get("/", "HTTP_COOKIE" =>
|
|
87
|
-
tampered_with_cookie)
|
|
88
|
-
|
|
89
|
-
# The tampered-with cookie is ignored, so we get back an identical Set-Cookie
|
|
90
|
-
response2["Set-Cookie"].should.equal(response1["Set-Cookie"])
|
|
91
|
-
end
|
|
92
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
require 'test/spec'
|
|
2
|
-
|
|
3
|
-
require 'rack/showexceptions'
|
|
4
|
-
require 'rack/mock'
|
|
5
|
-
|
|
6
|
-
context "Rack::ShowExceptions" do
|
|
7
|
-
specify "catches exceptions" do
|
|
8
|
-
res = nil
|
|
9
|
-
req = Rack::MockRequest.new(Rack::ShowExceptions.new(lambda { |env|
|
|
10
|
-
raise RuntimeError
|
|
11
|
-
}))
|
|
12
|
-
lambda {
|
|
13
|
-
res = req.get("/")
|
|
14
|
-
}.should.not.raise
|
|
15
|
-
res.should.be.a.server_error
|
|
16
|
-
res.status.should.equal 500
|
|
17
|
-
|
|
18
|
-
res.should =~ /RuntimeError/
|
|
19
|
-
res.should =~ /ShowExceptions/
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
require 'test/spec'
|
|
2
|
-
|
|
3
|
-
require 'rack/showstatus'
|
|
4
|
-
require 'rack/mock'
|
|
5
|
-
|
|
6
|
-
context "Rack::ShowStatus" do
|
|
7
|
-
specify "should provide a default status message" do
|
|
8
|
-
req = Rack::MockRequest.new(Rack::ShowStatus.new(lambda { |env|
|
|
9
|
-
[404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
|
|
10
|
-
}))
|
|
11
|
-
|
|
12
|
-
res = req.get("/", :lint => true)
|
|
13
|
-
res.should.be.not_found
|
|
14
|
-
res.should.be.not.empty
|
|
15
|
-
|
|
16
|
-
res["Content-Type"].should.equal("text/html")
|
|
17
|
-
res.should =~ /404/
|
|
18
|
-
res.should =~ /Not Found/
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
specify "should let the app provide additional information" do
|
|
22
|
-
req = Rack::MockRequest.new(Rack::ShowStatus.new(lambda { |env|
|
|
23
|
-
env["rack.showstatus.detail"] = "gone too meta."
|
|
24
|
-
[404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
|
|
25
|
-
}))
|
|
26
|
-
|
|
27
|
-
res = req.get("/", :lint => true)
|
|
28
|
-
res.should.be.not_found
|
|
29
|
-
res.should.be.not.empty
|
|
30
|
-
|
|
31
|
-
res["Content-Type"].should.equal("text/html")
|
|
32
|
-
res.should =~ /404/
|
|
33
|
-
res.should =~ /Not Found/
|
|
34
|
-
res.should =~ /too meta/
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
specify "should not replace existing messages" do
|
|
38
|
-
req = Rack::MockRequest.new(Rack::ShowStatus.new(lambda { |env|
|
|
39
|
-
[404, {"Content-Type" => "text/plain", "Content-Length" => "4"}, ["foo!"]]
|
|
40
|
-
}))
|
|
41
|
-
res = req.get("/", :lint => true)
|
|
42
|
-
res.should.be.not_found
|
|
43
|
-
|
|
44
|
-
res.body.should == "foo!"
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
specify "should pass on original headers" do
|
|
48
|
-
headers = {"WWW-Authenticate" => "Basic blah"}
|
|
49
|
-
|
|
50
|
-
req = Rack::MockRequest.new(Rack::ShowStatus.new(lambda { |env| [401, headers, []] }))
|
|
51
|
-
res = req.get("/", :lint => true)
|
|
52
|
-
|
|
53
|
-
res["WWW-Authenticate"].should.equal("Basic blah")
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
specify "should replace existing messages if there is detail" do
|
|
57
|
-
req = Rack::MockRequest.new(Rack::ShowStatus.new(lambda { |env|
|
|
58
|
-
env["rack.showstatus.detail"] = "gone too meta."
|
|
59
|
-
[404, {"Content-Type" => "text/plain", "Content-Length" => "4"}, ["foo!"]]
|
|
60
|
-
}))
|
|
61
|
-
|
|
62
|
-
res = req.get("/", :lint => true)
|
|
63
|
-
res.should.be.not_found
|
|
64
|
-
res.should.be.not.empty
|
|
65
|
-
|
|
66
|
-
res["Content-Type"].should.equal("text/html")
|
|
67
|
-
res["Content-Length"].should.not.equal("4")
|
|
68
|
-
res.should =~ /404/
|
|
69
|
-
res.should =~ /too meta/
|
|
70
|
-
res.body.should.not =~ /foo/
|
|
71
|
-
end
|
|
72
|
-
end
|
data/test/spec_rack_static.rb
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
require 'test/spec'
|
|
2
|
-
|
|
3
|
-
require 'rack/static'
|
|
4
|
-
require 'rack/mock'
|
|
5
|
-
|
|
6
|
-
class DummyApp
|
|
7
|
-
def call(env)
|
|
8
|
-
[200, {}, ["Hello World"]]
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
context "Rack::Static" do
|
|
13
|
-
root = File.expand_path(File.dirname(__FILE__))
|
|
14
|
-
OPTIONS = {:urls => ["/cgi"], :root => root}
|
|
15
|
-
|
|
16
|
-
setup do
|
|
17
|
-
@request = Rack::MockRequest.new(Rack::Static.new(DummyApp.new, OPTIONS))
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
specify "serves files" do
|
|
21
|
-
res = @request.get("/cgi/test")
|
|
22
|
-
res.should.be.ok
|
|
23
|
-
res.body.should =~ /ruby/
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
specify "404s if url root is known but it can't find the file" do
|
|
27
|
-
res = @request.get("/cgi/foo")
|
|
28
|
-
res.should.be.not_found
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
specify "calls down the chain if url root is not known" do
|
|
32
|
-
res = @request.get("/something/else")
|
|
33
|
-
res.should.be.ok
|
|
34
|
-
res.body.should == "Hello World"
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
end
|