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
|
@@ -1,35 +1,44 @@
|
|
|
1
1
|
require 'yaml'
|
|
2
|
+
require 'rack/lint'
|
|
2
3
|
require 'rack/mock'
|
|
3
|
-
require '
|
|
4
|
-
require 'rack/response'
|
|
4
|
+
require 'stringio'
|
|
5
5
|
|
|
6
|
-
app = lambda { |env|
|
|
6
|
+
app = Rack::Lint.new(lambda { |env|
|
|
7
7
|
req = Rack::Request.new(env)
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
env["mock.postdata"] = env["rack.input"].read
|
|
10
10
|
if req.GET["error"]
|
|
11
11
|
env["rack.errors"].puts req.GET["error"]
|
|
12
12
|
env["rack.errors"].flush
|
|
13
13
|
end
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
|
|
15
|
+
body = req.head? ? "" : env.to_yaml
|
|
16
|
+
Rack::Response.new(body,
|
|
16
17
|
req.GET["status"] || 200,
|
|
17
18
|
"Content-Type" => "text/yaml").finish
|
|
18
|
-
}
|
|
19
|
+
})
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
describe Rack::MockRequest do
|
|
22
|
+
should "return a MockResponse" do
|
|
22
23
|
res = Rack::MockRequest.new(app).get("")
|
|
23
24
|
res.should.be.kind_of Rack::MockResponse
|
|
24
25
|
end
|
|
25
26
|
|
|
26
|
-
|
|
27
|
+
should "be able to only return the environment" do
|
|
27
28
|
env = Rack::MockRequest.env_for("")
|
|
28
29
|
env.should.be.kind_of Hash
|
|
29
30
|
env.should.include "rack.version"
|
|
30
31
|
end
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
should "return an environment with a path" do
|
|
34
|
+
env = Rack::MockRequest.env_for("http://www.example.com/parse?location[]=1&location[]=2&age_group[]=2")
|
|
35
|
+
env["QUERY_STRING"].should.equal "location[]=1&location[]=2&age_group[]=2"
|
|
36
|
+
env["PATH_INFO"].should.equal "/parse"
|
|
37
|
+
env.should.be.kind_of Hash
|
|
38
|
+
env.should.include "rack.version"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
should "provide sensible defaults" do
|
|
33
42
|
res = Rack::MockRequest.new(app).request
|
|
34
43
|
|
|
35
44
|
env = YAML.load(res.body)
|
|
@@ -43,7 +52,7 @@ context "Rack::MockRequest" do
|
|
|
43
52
|
env["mock.postdata"].should.be.empty
|
|
44
53
|
end
|
|
45
54
|
|
|
46
|
-
|
|
55
|
+
should "allow GET/POST/PUT/DELETE/HEAD" do
|
|
47
56
|
res = Rack::MockRequest.new(app).get("", :input => "foo")
|
|
48
57
|
env = YAML.load(res.body)
|
|
49
58
|
env["REQUEST_METHOD"].should.equal "GET"
|
|
@@ -56,20 +65,27 @@ context "Rack::MockRequest" do
|
|
|
56
65
|
env = YAML.load(res.body)
|
|
57
66
|
env["REQUEST_METHOD"].should.equal "PUT"
|
|
58
67
|
|
|
68
|
+
res = Rack::MockRequest.new(app).patch("", :input => "foo")
|
|
69
|
+
env = YAML.load(res.body)
|
|
70
|
+
env["REQUEST_METHOD"].should.equal "PATCH"
|
|
71
|
+
|
|
59
72
|
res = Rack::MockRequest.new(app).delete("", :input => "foo")
|
|
60
73
|
env = YAML.load(res.body)
|
|
61
74
|
env["REQUEST_METHOD"].should.equal "DELETE"
|
|
75
|
+
|
|
76
|
+
Rack::MockRequest.env_for("/", :method => "HEAD")["REQUEST_METHOD"].
|
|
77
|
+
should.equal "HEAD"
|
|
62
78
|
|
|
63
79
|
Rack::MockRequest.env_for("/", :method => "OPTIONS")["REQUEST_METHOD"].
|
|
64
80
|
should.equal "OPTIONS"
|
|
65
81
|
end
|
|
66
82
|
|
|
67
|
-
|
|
83
|
+
should "set content length" do
|
|
68
84
|
env = Rack::MockRequest.env_for("/", :input => "foo")
|
|
69
85
|
env["CONTENT_LENGTH"].should.equal "3"
|
|
70
86
|
end
|
|
71
87
|
|
|
72
|
-
|
|
88
|
+
should "allow posting" do
|
|
73
89
|
res = Rack::MockRequest.new(app).get("", :input => "foo")
|
|
74
90
|
env = YAML.load(res.body)
|
|
75
91
|
env["mock.postdata"].should.equal "foo"
|
|
@@ -79,7 +95,7 @@ context "Rack::MockRequest" do
|
|
|
79
95
|
env["mock.postdata"].should.equal "foo"
|
|
80
96
|
end
|
|
81
97
|
|
|
82
|
-
|
|
98
|
+
should "use all parts of an URL" do
|
|
83
99
|
res = Rack::MockRequest.new(app).
|
|
84
100
|
get("https://bla.example.org:9292/meh/foo?bar")
|
|
85
101
|
res.should.be.kind_of Rack::MockResponse
|
|
@@ -93,7 +109,7 @@ context "Rack::MockRequest" do
|
|
|
93
109
|
env["rack.url_scheme"].should.equal "https"
|
|
94
110
|
end
|
|
95
111
|
|
|
96
|
-
|
|
112
|
+
should "set SSL port and HTTP flag on when using https" do
|
|
97
113
|
res = Rack::MockRequest.new(app).
|
|
98
114
|
get("https://example.org/foo")
|
|
99
115
|
res.should.be.kind_of Rack::MockResponse
|
|
@@ -108,7 +124,7 @@ context "Rack::MockRequest" do
|
|
|
108
124
|
env["HTTPS"].should.equal "on"
|
|
109
125
|
end
|
|
110
126
|
|
|
111
|
-
|
|
127
|
+
should "prepend slash to uri path" do
|
|
112
128
|
res = Rack::MockRequest.new(app).
|
|
113
129
|
get("foo")
|
|
114
130
|
res.should.be.kind_of Rack::MockResponse
|
|
@@ -122,33 +138,33 @@ context "Rack::MockRequest" do
|
|
|
122
138
|
env["rack.url_scheme"].should.equal "http"
|
|
123
139
|
end
|
|
124
140
|
|
|
125
|
-
|
|
141
|
+
should "properly convert method name to an uppercase string" do
|
|
126
142
|
res = Rack::MockRequest.new(app).request(:get)
|
|
127
143
|
env = YAML.load(res.body)
|
|
128
144
|
env["REQUEST_METHOD"].should.equal "GET"
|
|
129
145
|
end
|
|
130
146
|
|
|
131
|
-
|
|
147
|
+
should "accept params and build query string for GET requests" do
|
|
132
148
|
res = Rack::MockRequest.new(app).get("/foo?baz=2", :params => {:foo => {:bar => "1"}})
|
|
133
149
|
env = YAML.load(res.body)
|
|
134
150
|
env["REQUEST_METHOD"].should.equal "GET"
|
|
135
|
-
env["QUERY_STRING"].should.
|
|
136
|
-
env["QUERY_STRING"].should.
|
|
151
|
+
env["QUERY_STRING"].should.include "baz=2"
|
|
152
|
+
env["QUERY_STRING"].should.include "foo[bar]=1"
|
|
137
153
|
env["PATH_INFO"].should.equal "/foo"
|
|
138
154
|
env["mock.postdata"].should.equal ""
|
|
139
155
|
end
|
|
140
156
|
|
|
141
|
-
|
|
157
|
+
should "accept raw input in params for GET requests" do
|
|
142
158
|
res = Rack::MockRequest.new(app).get("/foo?baz=2", :params => "foo[bar]=1")
|
|
143
159
|
env = YAML.load(res.body)
|
|
144
160
|
env["REQUEST_METHOD"].should.equal "GET"
|
|
145
|
-
env["QUERY_STRING"].should.
|
|
146
|
-
env["QUERY_STRING"].should.
|
|
161
|
+
env["QUERY_STRING"].should.include "baz=2"
|
|
162
|
+
env["QUERY_STRING"].should.include "foo[bar]=1"
|
|
147
163
|
env["PATH_INFO"].should.equal "/foo"
|
|
148
164
|
env["mock.postdata"].should.equal ""
|
|
149
165
|
end
|
|
150
166
|
|
|
151
|
-
|
|
167
|
+
should "accept params and build url encoded params for POST requests" do
|
|
152
168
|
res = Rack::MockRequest.new(app).post("/foo", :params => {:foo => {:bar => "1"}})
|
|
153
169
|
env = YAML.load(res.body)
|
|
154
170
|
env["REQUEST_METHOD"].should.equal "POST"
|
|
@@ -158,7 +174,7 @@ context "Rack::MockRequest" do
|
|
|
158
174
|
env["mock.postdata"].should.equal "foo[bar]=1"
|
|
159
175
|
end
|
|
160
176
|
|
|
161
|
-
|
|
177
|
+
should "accept raw input in params for POST requests" do
|
|
162
178
|
res = Rack::MockRequest.new(app).post("/foo", :params => "foo[bar]=1")
|
|
163
179
|
env = YAML.load(res.body)
|
|
164
180
|
env["REQUEST_METHOD"].should.equal "POST"
|
|
@@ -168,27 +184,57 @@ context "Rack::MockRequest" do
|
|
|
168
184
|
env["mock.postdata"].should.equal "foo[bar]=1"
|
|
169
185
|
end
|
|
170
186
|
|
|
171
|
-
|
|
172
|
-
files = Rack::
|
|
187
|
+
should "accept params and build multipart encoded params for POST requests" do
|
|
188
|
+
files = Rack::Multipart::UploadedFile.new(File.join(File.dirname(__FILE__), "multipart", "file1.txt"))
|
|
173
189
|
res = Rack::MockRequest.new(app).post("/foo", :params => { "submit-name" => "Larry", "files" => files })
|
|
174
190
|
env = YAML.load(res.body)
|
|
175
191
|
env["REQUEST_METHOD"].should.equal "POST"
|
|
176
192
|
env["QUERY_STRING"].should.equal ""
|
|
177
193
|
env["PATH_INFO"].should.equal "/foo"
|
|
178
194
|
env["CONTENT_TYPE"].should.equal "multipart/form-data; boundary=AaB03x"
|
|
179
|
-
|
|
195
|
+
# The gsub accounts for differences in YAMLs affect on the data.
|
|
196
|
+
env["mock.postdata"].gsub("\r", "").length.should.equal 206
|
|
180
197
|
end
|
|
181
198
|
|
|
182
|
-
|
|
199
|
+
should "behave valid according to the Rack spec" do
|
|
183
200
|
lambda {
|
|
184
|
-
|
|
201
|
+
Rack::MockRequest.new(app).
|
|
185
202
|
get("https://bla.example.org:9292/meh/foo?bar", :lint => true)
|
|
186
203
|
}.should.not.raise(Rack::Lint::LintError)
|
|
187
204
|
end
|
|
205
|
+
|
|
206
|
+
should "call close on the original body object" do
|
|
207
|
+
called = false
|
|
208
|
+
body = Rack::BodyProxy.new(['hi']) { called = true }
|
|
209
|
+
capp = proc { |e| [200, {'Content-Type' => 'text/plain'}, body] }
|
|
210
|
+
called.should.equal false
|
|
211
|
+
Rack::MockRequest.new(capp).get('/', :lint => true)
|
|
212
|
+
called.should.equal true
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
if "<3".respond_to? :b
|
|
216
|
+
should "defaults encoding to ASCII 8BIT" do
|
|
217
|
+
req = Rack::MockRequest.env_for("/foo")
|
|
218
|
+
|
|
219
|
+
keys = [
|
|
220
|
+
Rack::REQUEST_METHOD,
|
|
221
|
+
"SERVER_NAME",
|
|
222
|
+
"SERVER_PORT",
|
|
223
|
+
Rack::QUERY_STRING,
|
|
224
|
+
Rack::PATH_INFO,
|
|
225
|
+
"rack.url_scheme",
|
|
226
|
+
"HTTPS"
|
|
227
|
+
]
|
|
228
|
+
|
|
229
|
+
keys.each do |k|
|
|
230
|
+
req[k].encoding.should.equal Encoding::ASCII_8BIT
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
end
|
|
188
234
|
end
|
|
189
235
|
|
|
190
|
-
|
|
191
|
-
|
|
236
|
+
describe Rack::MockResponse do
|
|
237
|
+
should "provide access to the HTTP status" do
|
|
192
238
|
res = Rack::MockRequest.new(app).get("")
|
|
193
239
|
res.should.be.successful
|
|
194
240
|
res.should.be.ok
|
|
@@ -209,18 +255,18 @@ context "Rack::MockResponse" do
|
|
|
209
255
|
res.should.be.empty
|
|
210
256
|
end
|
|
211
257
|
|
|
212
|
-
|
|
258
|
+
should "provide access to the HTTP headers" do
|
|
213
259
|
res = Rack::MockRequest.new(app).get("")
|
|
214
260
|
res.should.include "Content-Type"
|
|
215
261
|
res.headers["Content-Type"].should.equal "text/yaml"
|
|
216
262
|
res.original_headers["Content-Type"].should.equal "text/yaml"
|
|
217
263
|
res["Content-Type"].should.equal "text/yaml"
|
|
218
264
|
res.content_type.should.equal "text/yaml"
|
|
219
|
-
res.content_length.should.
|
|
265
|
+
res.content_length.should.not.equal 0
|
|
220
266
|
res.location.should.be.nil
|
|
221
267
|
end
|
|
222
268
|
|
|
223
|
-
|
|
269
|
+
should "provide access to the HTTP body" do
|
|
224
270
|
res = Rack::MockRequest.new(app).get("")
|
|
225
271
|
res.body.should =~ /rack/
|
|
226
272
|
res.should =~ /rack/
|
|
@@ -228,14 +274,22 @@ context "Rack::MockResponse" do
|
|
|
228
274
|
res.should.satisfy { |r| r.match(/rack/) }
|
|
229
275
|
end
|
|
230
276
|
|
|
231
|
-
|
|
277
|
+
should "provide access to the Rack errors" do
|
|
232
278
|
res = Rack::MockRequest.new(app).get("/?error=foo", :lint => true)
|
|
233
279
|
res.should.be.ok
|
|
234
280
|
res.errors.should.not.be.empty
|
|
235
281
|
res.errors.should.include "foo"
|
|
236
282
|
end
|
|
237
283
|
|
|
238
|
-
|
|
284
|
+
should "allow calling body.close afterwards" do
|
|
285
|
+
# this is exactly what rack-test does
|
|
286
|
+
body = StringIO.new("hi")
|
|
287
|
+
res = Rack::MockResponse.new(200, {}, body)
|
|
288
|
+
body.close if body.respond_to?(:close)
|
|
289
|
+
res.body.should == 'hi'
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
should "optionally make Rack errors fatal" do
|
|
239
293
|
lambda {
|
|
240
294
|
Rack::MockRequest.new(app).get("/?error=foo", :fatal => true)
|
|
241
295
|
}.should.raise(Rack::MockRequest::FatalWarning)
|
|
@@ -1,53 +1,48 @@
|
|
|
1
|
-
require 'test/spec'
|
|
2
|
-
|
|
3
1
|
begin
|
|
2
|
+
require 'rack'
|
|
4
3
|
require 'rack/handler/mongrel'
|
|
5
|
-
require '
|
|
6
|
-
require 'rack/lint'
|
|
7
|
-
require 'testrequest'
|
|
4
|
+
require File.expand_path('../testrequest', __FILE__)
|
|
8
5
|
require 'timeout'
|
|
9
6
|
|
|
10
7
|
Thread.abort_on_exception = true
|
|
11
8
|
$tcp_defer_accept_opts = nil
|
|
12
9
|
$tcp_cork_opts = nil
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
describe Rack::Handler::Mongrel do
|
|
12
|
+
extend TestRequest::Helpers
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
@acc = server.run
|
|
24
|
-
end
|
|
14
|
+
@server = Mongrel::HttpServer.new(@host='127.0.0.1', @port=9201)
|
|
15
|
+
@server.register('/test',
|
|
16
|
+
Rack::Handler::Mongrel.new(Rack::Lint.new(TestRequest.new)))
|
|
17
|
+
@server.register('/stream',
|
|
18
|
+
Rack::Handler::Mongrel.new(Rack::Lint.new(StreamingRequest)))
|
|
19
|
+
@acc = @server.run
|
|
25
20
|
|
|
26
|
-
|
|
21
|
+
should "respond" do
|
|
27
22
|
lambda {
|
|
28
23
|
GET("/test")
|
|
29
24
|
}.should.not.raise
|
|
30
25
|
end
|
|
31
26
|
|
|
32
|
-
|
|
27
|
+
should "be a Mongrel" do
|
|
33
28
|
GET("/test")
|
|
34
|
-
status.should.
|
|
29
|
+
status.should.equal 200
|
|
35
30
|
response["SERVER_SOFTWARE"].should =~ /Mongrel/
|
|
36
31
|
response["HTTP_VERSION"].should.equal "HTTP/1.1"
|
|
37
32
|
response["SERVER_PROTOCOL"].should.equal "HTTP/1.1"
|
|
38
33
|
response["SERVER_PORT"].should.equal "9201"
|
|
39
|
-
response["SERVER_NAME"].should.equal "
|
|
34
|
+
response["SERVER_NAME"].should.equal "127.0.0.1"
|
|
40
35
|
end
|
|
41
36
|
|
|
42
|
-
|
|
37
|
+
should "have rack headers" do
|
|
43
38
|
GET("/test")
|
|
44
|
-
response["rack.version"].should.equal [1,
|
|
45
|
-
response["rack.multithread"].should.be
|
|
46
|
-
response["rack.multiprocess"].should.be
|
|
47
|
-
response["rack.run_once"].should.be
|
|
39
|
+
response["rack.version"].should.equal [1,3]
|
|
40
|
+
response["rack.multithread"].should.be.true
|
|
41
|
+
response["rack.multiprocess"].should.be.false
|
|
42
|
+
response["rack.run_once"].should.be.false
|
|
48
43
|
end
|
|
49
44
|
|
|
50
|
-
|
|
45
|
+
should "have CGI headers on GET" do
|
|
51
46
|
GET("/test")
|
|
52
47
|
response["REQUEST_METHOD"].should.equal "GET"
|
|
53
48
|
response["SCRIPT_NAME"].should.equal "/test"
|
|
@@ -64,7 +59,7 @@ context "Rack::Handler::Mongrel" do
|
|
|
64
59
|
response["QUERY_STRING"].should.equal "quux=1"
|
|
65
60
|
end
|
|
66
61
|
|
|
67
|
-
|
|
62
|
+
should "have CGI headers on POST" do
|
|
68
63
|
POST("/test", {"rack-form-data" => "23"}, {'X-test-header' => '42'})
|
|
69
64
|
status.should.equal 200
|
|
70
65
|
response["REQUEST_METHOD"].should.equal "POST"
|
|
@@ -75,36 +70,36 @@ context "Rack::Handler::Mongrel" do
|
|
|
75
70
|
response["test.postdata"].should.equal "rack-form-data=23"
|
|
76
71
|
end
|
|
77
72
|
|
|
78
|
-
|
|
73
|
+
should "support HTTP auth" do
|
|
79
74
|
GET("/test", {:user => "ruth", :passwd => "secret"})
|
|
80
75
|
response["HTTP_AUTHORIZATION"].should.equal "Basic cnV0aDpzZWNyZXQ="
|
|
81
76
|
end
|
|
82
77
|
|
|
83
|
-
|
|
78
|
+
should "set status" do
|
|
84
79
|
GET("/test?secret")
|
|
85
80
|
status.should.equal 403
|
|
86
81
|
response["rack.url_scheme"].should.equal "http"
|
|
87
82
|
end
|
|
88
83
|
|
|
89
|
-
|
|
84
|
+
should "provide a .run" do
|
|
90
85
|
block_ran = false
|
|
91
86
|
Thread.new {
|
|
92
|
-
Rack::Handler::Mongrel.run(lambda {}, {:Port => 9211}) { |server|
|
|
87
|
+
Rack::Handler::Mongrel.run(lambda {}, {:Host => '127.0.0.1', :Port => 9211}) { |server|
|
|
93
88
|
server.should.be.kind_of Mongrel::HttpServer
|
|
94
89
|
block_ran = true
|
|
95
90
|
}
|
|
96
91
|
}
|
|
97
92
|
sleep 1
|
|
98
|
-
block_ran.should.be
|
|
93
|
+
block_ran.should.be.true
|
|
99
94
|
end
|
|
100
95
|
|
|
101
|
-
|
|
96
|
+
should "provide a .run that maps a hash" do
|
|
102
97
|
block_ran = false
|
|
103
98
|
Thread.new {
|
|
104
99
|
map = {'/'=>lambda{},'/foo'=>lambda{}}
|
|
105
|
-
Rack::Handler::Mongrel.run(map, :map => true, :Port => 9221) { |server|
|
|
100
|
+
Rack::Handler::Mongrel.run(map, :map => true, :Host => '127.0.0.1', :Port => 9221) { |server|
|
|
106
101
|
server.should.be.kind_of Mongrel::HttpServer
|
|
107
|
-
server.classifier.uris.size.should.
|
|
102
|
+
server.classifier.uris.size.should.equal 2
|
|
108
103
|
server.classifier.uris.should.not.include '/arf'
|
|
109
104
|
server.classifier.uris.should.include '/'
|
|
110
105
|
server.classifier.uris.should.include '/foo'
|
|
@@ -112,16 +107,16 @@ context "Rack::Handler::Mongrel" do
|
|
|
112
107
|
}
|
|
113
108
|
}
|
|
114
109
|
sleep 1
|
|
115
|
-
block_ran.should.be
|
|
110
|
+
block_ran.should.be.true
|
|
116
111
|
end
|
|
117
112
|
|
|
118
|
-
|
|
113
|
+
should "provide a .run that maps a urlmap" do
|
|
119
114
|
block_ran = false
|
|
120
115
|
Thread.new {
|
|
121
116
|
map = Rack::URLMap.new({'/'=>lambda{},'/bar'=>lambda{}})
|
|
122
|
-
Rack::Handler::Mongrel.run(map, {:map => true, :Port => 9231}) { |server|
|
|
117
|
+
Rack::Handler::Mongrel.run(map, {:map => true, :Host => '127.0.0.1', :Port => 9231}) { |server|
|
|
123
118
|
server.should.be.kind_of Mongrel::HttpServer
|
|
124
|
-
server.classifier.uris.size.should.
|
|
119
|
+
server.classifier.uris.size.should.equal 2
|
|
125
120
|
server.classifier.uris.should.not.include '/arf'
|
|
126
121
|
server.classifier.uris.should.include '/'
|
|
127
122
|
server.classifier.uris.should.include '/bar'
|
|
@@ -129,41 +124,41 @@ context "Rack::Handler::Mongrel" do
|
|
|
129
124
|
}
|
|
130
125
|
}
|
|
131
126
|
sleep 1
|
|
132
|
-
block_ran.should.be
|
|
127
|
+
block_ran.should.be.true
|
|
133
128
|
end
|
|
134
129
|
|
|
135
|
-
|
|
130
|
+
should "provide a .run that maps a urlmap restricting by host" do
|
|
136
131
|
block_ran = false
|
|
137
132
|
Thread.new {
|
|
138
133
|
map = Rack::URLMap.new({
|
|
139
134
|
'/' => lambda{},
|
|
140
135
|
'/foo' => lambda{},
|
|
141
136
|
'/bar' => lambda{},
|
|
142
|
-
'http://
|
|
143
|
-
'http://
|
|
137
|
+
'http://127.0.0.1/' => lambda{},
|
|
138
|
+
'http://127.0.0.1/bar' => lambda{},
|
|
144
139
|
'http://falsehost/arf' => lambda{},
|
|
145
140
|
'http://falsehost/qux' => lambda{}
|
|
146
141
|
})
|
|
147
|
-
opt = {:map => true, :Port => 9241, :Host => '
|
|
142
|
+
opt = {:map => true, :Port => 9241, :Host => '127.0.0.1'}
|
|
148
143
|
Rack::Handler::Mongrel.run(map, opt) { |server|
|
|
149
144
|
server.should.be.kind_of Mongrel::HttpServer
|
|
150
145
|
server.classifier.uris.should.include '/'
|
|
151
|
-
server.classifier.handler_map['/'].size.should.
|
|
146
|
+
server.classifier.handler_map['/'].size.should.equal 2
|
|
152
147
|
server.classifier.uris.should.include '/foo'
|
|
153
|
-
server.classifier.handler_map['/foo'].size.should.
|
|
148
|
+
server.classifier.handler_map['/foo'].size.should.equal 1
|
|
154
149
|
server.classifier.uris.should.include '/bar'
|
|
155
|
-
server.classifier.handler_map['/bar'].size.should.
|
|
150
|
+
server.classifier.handler_map['/bar'].size.should.equal 2
|
|
156
151
|
server.classifier.uris.should.not.include '/qux'
|
|
157
152
|
server.classifier.uris.should.not.include '/arf'
|
|
158
|
-
server.classifier.uris.size.should.
|
|
153
|
+
server.classifier.uris.size.should.equal 3
|
|
159
154
|
block_ran = true
|
|
160
155
|
}
|
|
161
156
|
}
|
|
162
157
|
sleep 1
|
|
163
|
-
block_ran.should.be
|
|
158
|
+
block_ran.should.be.true
|
|
164
159
|
end
|
|
165
160
|
|
|
166
|
-
|
|
161
|
+
should "stream #each part of the response" do
|
|
167
162
|
body = ''
|
|
168
163
|
begin
|
|
169
164
|
Timeout.timeout(1) do
|
|
@@ -179,11 +174,9 @@ context "Rack::Handler::Mongrel" do
|
|
|
179
174
|
body.should.not.be.empty
|
|
180
175
|
end
|
|
181
176
|
|
|
182
|
-
|
|
183
|
-
@acc.raise Mongrel::StopServer
|
|
184
|
-
end
|
|
177
|
+
@acc.raise Mongrel::StopServer
|
|
185
178
|
end
|
|
186
179
|
|
|
187
180
|
rescue LoadError
|
|
188
|
-
|
|
181
|
+
warn "Skipping Rack::Handler::Mongrel tests (Mongrel is required). `gem install mongrel` and try again."
|
|
189
182
|
end
|