rack 1.1.0 → 1.2.0
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/README +23 -26
- data/SPEC +3 -3
- data/lib/rack/auth/digest/params.rb +1 -1
- data/lib/rack/content_length.rb +1 -1
- data/lib/rack/etag.rb +15 -6
- data/lib/rack/file.rb +3 -1
- data/lib/rack/handler/cgi.rb +8 -7
- data/lib/rack/handler/fastcgi.rb +1 -1
- data/lib/rack/handler/lsws.rb +1 -1
- data/lib/rack/handler/mongrel.rb +1 -1
- data/lib/rack/handler/scgi.rb +1 -4
- data/lib/rack/handler/webrick.rb +10 -6
- data/lib/rack/lint.rb +29 -37
- data/lib/rack/mime.rb +2 -0
- data/lib/rack/mock.rb +2 -1
- data/lib/rack/recursive.rb +4 -0
- data/lib/rack/request.rb +8 -6
- data/lib/rack/response.rb +1 -0
- data/lib/rack/rewindable_input.rb +13 -10
- data/lib/rack/sendfile.rb +8 -6
- data/lib/rack/server.rb +66 -7
- data/lib/rack/session/memcache.rb +1 -1
- data/lib/rack/urlmap.rb +6 -7
- data/lib/rack/utils.rb +64 -22
- data/lib/rack.rb +1 -12
- data/rack.gemspec +6 -6
- data/spec/cgi/lighttpd.conf +25 -0
- data/spec/cgi/rackup_stub.rb +6 -0
- data/spec/cgi/sample_rackup.ru +5 -0
- data/spec/cgi/test +9 -0
- data/spec/cgi/test.fcgi +8 -0
- data/spec/cgi/test.ru +5 -0
- data/spec/multipart/bad_robots +259 -0
- data/spec/multipart/binary +0 -0
- data/spec/multipart/empty +10 -0
- data/spec/multipart/fail_16384_nofile +814 -0
- data/spec/multipart/file1.txt +1 -0
- data/spec/multipart/filename_and_modification_param +7 -0
- data/spec/multipart/filename_with_escaped_quotes +6 -0
- data/spec/multipart/filename_with_escaped_quotes_and_modification_param +7 -0
- data/spec/multipart/filename_with_percent_escaped_quotes +6 -0
- data/spec/multipart/filename_with_unescaped_quotes +6 -0
- data/spec/multipart/ie +6 -0
- data/spec/multipart/nested +10 -0
- data/spec/multipart/none +9 -0
- data/spec/multipart/semicolon +6 -0
- data/spec/multipart/text +10 -0
- data/spec/rackup/config.ru +31 -0
- data/{test/spec_rack_auth_basic.rb → spec/spec_auth_basic.rb} +11 -14
- data/{test/spec_rack_auth_digest.rb → spec/spec_auth_digest.rb} +18 -21
- data/{test/spec_rack_builder.rb → spec/spec_builder.rb} +49 -10
- data/{test/spec_rack_cascade.rb → spec/spec_cascade.rb} +7 -10
- data/{test/spec_rack_cgi.rb → spec/spec_cgi.rb} +34 -32
- data/{test/spec_rack_chunked.rb → spec/spec_chunked.rb} +8 -10
- data/{test/spec_rack_commonlogger.rb → spec/spec_commonlogger.rb} +10 -15
- data/{test/spec_rack_conditionalget.rb → spec/spec_conditionalget.rb} +5 -7
- data/{test/spec_rack_config.rb → spec/spec_config.rb} +6 -7
- data/{test/spec_rack_content_length.rb → spec/spec_content_length.rb} +7 -8
- data/{test/spec_rack_content_type.rb → spec/spec_content_type.rb} +5 -6
- data/{test/spec_rack_deflater.rb → spec/spec_deflater.rb} +11 -13
- data/{test/spec_rack_directory.rb → spec/spec_directory.rb} +6 -10
- data/{test/spec_rack_etag.rb → spec/spec_etag.rb} +3 -5
- data/{test/spec_rack_fastcgi.rb → spec/spec_fastcgi.rb} +36 -29
- data/{test/spec_rack_file.rb → spec/spec_file.rb} +9 -13
- data/{test/spec_rack_handler.rb → spec/spec_handler.rb} +10 -12
- data/{test/spec_rack_head.rb → spec/spec_head.rb} +3 -3
- data/{test/spec_rack_lint.rb → spec/spec_lint.rb} +19 -32
- data/{test/spec_rack_lobster.rb → spec/spec_lobster.rb} +9 -11
- data/{test/spec_rack_lock.rb → spec/spec_lock.rb} +15 -17
- data/{test/spec_rack_logger.rb → spec/spec_logger.rb} +6 -7
- data/{test/spec_rack_methodoverride.rb → spec/spec_methodoverride.rb} +15 -17
- data/{test/spec_rack_mock.rb → spec/spec_mock.rb} +30 -32
- data/{test/spec_rack_mongrel.rb → spec/spec_mongrel.rb} +40 -46
- data/{test/spec_rack_nulllogger.rb → spec/spec_nulllogger.rb} +4 -5
- data/{test/spec_rack_recursive.rb → spec/spec_recursive.rb} +28 -36
- data/{test/spec_rack_request.rb → spec/spec_request.rb} +84 -49
- data/{test/spec_rack_response.rb → spec/spec_response.rb} +48 -29
- data/spec/spec_rewindable_input.rb +118 -0
- data/{test/spec_rack_runtime.rb → spec/spec_runtime.rb} +15 -11
- data/{test/spec_rack_sendfile.rb → spec/spec_sendfile.rb} +11 -14
- data/{test/spec_rack_session_cookie.rb → spec/spec_session_cookie.rb} +15 -18
- data/{test/spec_rack_session_memcache.rb → spec/spec_session_memcache.rb} +32 -26
- data/{test/spec_rack_session_pool.rb → spec/spec_session_pool.rb} +36 -31
- data/spec/spec_showexceptions.rb +23 -0
- data/spec/spec_showstatus.rb +79 -0
- data/{test/spec_rack_static.rb → spec/spec_static.rb} +5 -9
- data/{test/spec_rack_thin.rb → spec/spec_thin.rb} +30 -35
- data/{test/spec_rack_urlmap.rb → spec/spec_urlmap.rb} +6 -8
- data/{test/spec_rack_utils.rb → spec/spec_utils.rb} +136 -71
- data/{test/spec_rack_webrick.rb → spec/spec_webrick.rb} +28 -36
- data/spec/testrequest.rb +77 -0
- data/spec/unregistered_handler/rack/handler/unregistered.rb +7 -0
- data/spec/unregistered_handler/rack/handler/unregistered_long_one.rb +7 -0
- metadata +206 -124
- data/RDOX +0 -0
- data/lib/rack/adapter/camping.rb +0 -22
- data/test/spec_rack_camping.rb +0 -51
- data/test/spec_rack_rewindable_input.rb +0 -118
- data/test/spec_rack_showexceptions.rb +0 -21
- data/test/spec_rack_showstatus.rb +0 -72
- data/test/spec_rackup.rb +0 -154
|
@@ -1,39 +1,40 @@
|
|
|
1
|
-
require 'test/spec'
|
|
2
|
-
|
|
3
|
-
require 'rack/session/pool'
|
|
4
|
-
require 'rack/mock'
|
|
5
|
-
require 'rack/response'
|
|
6
1
|
require 'thread'
|
|
2
|
+
require 'rack/mock'
|
|
3
|
+
require 'rack/session/pool'
|
|
7
4
|
|
|
8
|
-
|
|
5
|
+
describe Rack::Session::Pool do
|
|
9
6
|
session_key = Rack::Session::Pool::DEFAULT_OPTIONS[:key]
|
|
10
7
|
session_match = /#{session_key}=[0-9a-fA-F]+;/
|
|
8
|
+
|
|
11
9
|
incrementor = lambda do |env|
|
|
12
10
|
env["rack.session"]["counter"] ||= 0
|
|
13
11
|
env["rack.session"]["counter"] += 1
|
|
14
12
|
Rack::Response.new(env["rack.session"].inspect).to_a
|
|
15
13
|
end
|
|
16
|
-
|
|
14
|
+
|
|
15
|
+
drop_session = lambda do |env|
|
|
17
16
|
env['rack.session.options'][:drop] = true
|
|
18
17
|
incrementor.call(env)
|
|
19
18
|
end
|
|
20
|
-
|
|
19
|
+
|
|
20
|
+
renew_session = lambda do |env|
|
|
21
21
|
env['rack.session.options'][:renew] = true
|
|
22
22
|
incrementor.call(env)
|
|
23
23
|
end
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
defer_session = lambda do |env|
|
|
25
26
|
env['rack.session.options'][:defer] = true
|
|
26
27
|
incrementor.call(env)
|
|
27
28
|
end
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
it "creates a new cookie" do
|
|
30
31
|
pool = Rack::Session::Pool.new(incrementor)
|
|
31
32
|
res = Rack::MockRequest.new(pool).get("/")
|
|
32
33
|
res["Set-Cookie"].should.match session_match
|
|
33
34
|
res.body.should.equal '{"counter"=>1}'
|
|
34
35
|
end
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
it "determines session from a cookie" do
|
|
37
38
|
pool = Rack::Session::Pool.new(incrementor)
|
|
38
39
|
req = Rack::MockRequest.new(pool)
|
|
39
40
|
cookie = req.get("/")["Set-Cookie"]
|
|
@@ -43,14 +44,14 @@ context "Rack::Session::Pool" do
|
|
|
43
44
|
body.should.equal '{"counter"=>3}'
|
|
44
45
|
end
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
it "survives nonexistant cookies" do
|
|
47
48
|
pool = Rack::Session::Pool.new(incrementor)
|
|
48
49
|
res = Rack::MockRequest.new(pool).
|
|
49
50
|
get("/", "HTTP_COOKIE" => "#{session_key}=blarghfasel")
|
|
50
51
|
res.body.should.equal '{"counter"=>1}'
|
|
51
52
|
end
|
|
52
53
|
|
|
53
|
-
|
|
54
|
+
it "deletes cookies with :drop option" do
|
|
54
55
|
pool = Rack::Session::Pool.new(incrementor)
|
|
55
56
|
req = Rack::MockRequest.new(pool)
|
|
56
57
|
drop = Rack::Utils::Context.new(pool, drop_session)
|
|
@@ -59,25 +60,25 @@ context "Rack::Session::Pool" do
|
|
|
59
60
|
res0 = req.get("/")
|
|
60
61
|
session = (cookie = res0["Set-Cookie"])[session_match]
|
|
61
62
|
res0.body.should.equal '{"counter"=>1}'
|
|
62
|
-
pool.pool.size.should.
|
|
63
|
+
pool.pool.size.should.equal 1
|
|
63
64
|
|
|
64
65
|
res1 = req.get("/", "HTTP_COOKIE" => cookie)
|
|
65
66
|
res1["Set-Cookie"][session_match].should.equal session
|
|
66
67
|
res1.body.should.equal '{"counter"=>2}'
|
|
67
|
-
pool.pool.size.should.
|
|
68
|
+
pool.pool.size.should.equal 1
|
|
68
69
|
|
|
69
70
|
res2 = dreq.get("/", "HTTP_COOKIE" => cookie)
|
|
70
71
|
res2["Set-Cookie"].should.equal nil
|
|
71
72
|
res2.body.should.equal '{"counter"=>3}'
|
|
72
|
-
pool.pool.size.should.
|
|
73
|
+
pool.pool.size.should.equal 0
|
|
73
74
|
|
|
74
75
|
res3 = req.get("/", "HTTP_COOKIE" => cookie)
|
|
75
76
|
res3["Set-Cookie"][session_match].should.not.equal session
|
|
76
77
|
res3.body.should.equal '{"counter"=>1}'
|
|
77
|
-
pool.pool.size.should.
|
|
78
|
+
pool.pool.size.should.equal 1
|
|
78
79
|
end
|
|
79
80
|
|
|
80
|
-
|
|
81
|
+
it "provides new session id with :renew option" do
|
|
81
82
|
pool = Rack::Session::Pool.new(incrementor)
|
|
82
83
|
req = Rack::MockRequest.new(pool)
|
|
83
84
|
renew = Rack::Utils::Context.new(pool, renew_session)
|
|
@@ -86,27 +87,27 @@ context "Rack::Session::Pool" do
|
|
|
86
87
|
res0 = req.get("/")
|
|
87
88
|
session = (cookie = res0["Set-Cookie"])[session_match]
|
|
88
89
|
res0.body.should.equal '{"counter"=>1}'
|
|
89
|
-
pool.pool.size.should.
|
|
90
|
+
pool.pool.size.should.equal 1
|
|
90
91
|
|
|
91
92
|
res1 = req.get("/", "HTTP_COOKIE" => cookie)
|
|
92
93
|
res1["Set-Cookie"][session_match].should.equal session
|
|
93
94
|
res1.body.should.equal '{"counter"=>2}'
|
|
94
|
-
pool.pool.size.should.
|
|
95
|
+
pool.pool.size.should.equal 1
|
|
95
96
|
|
|
96
97
|
res2 = rreq.get("/", "HTTP_COOKIE" => cookie)
|
|
97
98
|
new_cookie = res2["Set-Cookie"]
|
|
98
99
|
new_session = new_cookie[session_match]
|
|
99
100
|
new_session.should.not.equal session
|
|
100
101
|
res2.body.should.equal '{"counter"=>3}'
|
|
101
|
-
pool.pool.size.should.
|
|
102
|
+
pool.pool.size.should.equal 1
|
|
102
103
|
|
|
103
104
|
res3 = req.get("/", "HTTP_COOKIE" => new_cookie)
|
|
104
105
|
res3["Set-Cookie"][session_match].should.equal new_session
|
|
105
106
|
res3.body.should.equal '{"counter"=>4}'
|
|
106
|
-
pool.pool.size.should.
|
|
107
|
+
pool.pool.size.should.equal 1
|
|
107
108
|
end
|
|
108
109
|
|
|
109
|
-
|
|
110
|
+
it "omits cookie with :defer option" do
|
|
110
111
|
pool = Rack::Session::Pool.new(incrementor)
|
|
111
112
|
req = Rack::MockRequest.new(pool)
|
|
112
113
|
defer = Rack::Utils::Context.new(pool, defer_session)
|
|
@@ -115,27 +116,31 @@ context "Rack::Session::Pool" do
|
|
|
115
116
|
res0 = req.get("/")
|
|
116
117
|
session = (cookie = res0["Set-Cookie"])[session_match]
|
|
117
118
|
res0.body.should.equal '{"counter"=>1}'
|
|
118
|
-
pool.pool.size.should.
|
|
119
|
+
pool.pool.size.should.equal 1
|
|
119
120
|
|
|
120
121
|
res1 = req.get("/", "HTTP_COOKIE" => cookie)
|
|
121
122
|
res1["Set-Cookie"][session_match].should.equal session
|
|
122
123
|
res1.body.should.equal '{"counter"=>2}'
|
|
123
|
-
pool.pool.size.should.
|
|
124
|
+
pool.pool.size.should.equal 1
|
|
124
125
|
|
|
125
126
|
res2 = dreq.get("/", "HTTP_COOKIE" => cookie)
|
|
126
127
|
res2["Set-Cookie"].should.equal nil
|
|
127
128
|
res2.body.should.equal '{"counter"=>3}'
|
|
128
|
-
pool.pool.size.should.
|
|
129
|
+
pool.pool.size.should.equal 1
|
|
129
130
|
|
|
130
131
|
res3 = req.get("/", "HTTP_COOKIE" => cookie)
|
|
131
132
|
res3["Set-Cookie"][session_match].should.equal session
|
|
132
133
|
res3.body.should.equal '{"counter"=>4}'
|
|
133
|
-
pool.pool.size.should.
|
|
134
|
+
pool.pool.size.should.equal 1
|
|
134
135
|
end
|
|
135
136
|
|
|
136
137
|
# anyone know how to do this better?
|
|
137
|
-
|
|
138
|
-
|
|
138
|
+
it "should merge sessions when multithreaded" do
|
|
139
|
+
unless $DEBUG
|
|
140
|
+
1.should.equal 1
|
|
141
|
+
next
|
|
142
|
+
end
|
|
143
|
+
|
|
139
144
|
warn 'Running multithread tests for Session::Pool'
|
|
140
145
|
pool = Rack::Session::Pool.new(incrementor)
|
|
141
146
|
req = Rack::MockRequest.new(pool)
|
|
@@ -166,7 +171,7 @@ context "Rack::Session::Pool" do
|
|
|
166
171
|
end
|
|
167
172
|
|
|
168
173
|
session = pool.pool[sess_id]
|
|
169
|
-
session.size.should.
|
|
170
|
-
session['counter'].should.
|
|
174
|
+
session.size.should.equal tnum+1 # counter
|
|
175
|
+
session['counter'].should.equal 2 # meeeh
|
|
171
176
|
end
|
|
172
177
|
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'rack/showexceptions'
|
|
2
|
+
require 'rack/mock'
|
|
3
|
+
|
|
4
|
+
describe Rack::ShowExceptions do
|
|
5
|
+
it "catches exceptions" do
|
|
6
|
+
res = nil
|
|
7
|
+
|
|
8
|
+
req = Rack::MockRequest.new(
|
|
9
|
+
Rack::ShowExceptions.new(
|
|
10
|
+
lambda{|env| raise RuntimeError }
|
|
11
|
+
))
|
|
12
|
+
|
|
13
|
+
lambda{
|
|
14
|
+
res = req.get("/")
|
|
15
|
+
}.should.not.raise
|
|
16
|
+
|
|
17
|
+
res.should.be.a.server_error
|
|
18
|
+
res.status.should.equal 500
|
|
19
|
+
|
|
20
|
+
res.should =~ /RuntimeError/
|
|
21
|
+
res.should =~ /ShowExceptions/
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require 'rack/showstatus'
|
|
2
|
+
require 'rack/mock'
|
|
3
|
+
|
|
4
|
+
describe Rack::ShowStatus do
|
|
5
|
+
should "provide a default status message" do
|
|
6
|
+
req = Rack::MockRequest.new(
|
|
7
|
+
Rack::ShowStatus.new(lambda{|env|
|
|
8
|
+
[404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
|
|
9
|
+
}))
|
|
10
|
+
|
|
11
|
+
res = req.get("/", :lint => true)
|
|
12
|
+
res.should.be.not_found
|
|
13
|
+
res.should.be.not.empty
|
|
14
|
+
|
|
15
|
+
res["Content-Type"].should.equal("text/html")
|
|
16
|
+
res.should =~ /404/
|
|
17
|
+
res.should =~ /Not Found/
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
should "let the app provide additional information" do
|
|
21
|
+
req = Rack::MockRequest.new(
|
|
22
|
+
Rack::ShowStatus.new(
|
|
23
|
+
lambda{|env|
|
|
24
|
+
env["rack.showstatus.detail"] = "gone too meta."
|
|
25
|
+
[404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
|
|
26
|
+
}))
|
|
27
|
+
|
|
28
|
+
res = req.get("/", :lint => true)
|
|
29
|
+
res.should.be.not_found
|
|
30
|
+
res.should.be.not.empty
|
|
31
|
+
|
|
32
|
+
res["Content-Type"].should.equal("text/html")
|
|
33
|
+
res.should =~ /404/
|
|
34
|
+
res.should =~ /Not Found/
|
|
35
|
+
res.should =~ /too meta/
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
should "not replace existing messages" do
|
|
39
|
+
req = Rack::MockRequest.new(
|
|
40
|
+
Rack::ShowStatus.new(
|
|
41
|
+
lambda{|env|
|
|
42
|
+
[404, {"Content-Type" => "text/plain", "Content-Length" => "4"}, ["foo!"]]
|
|
43
|
+
}))
|
|
44
|
+
|
|
45
|
+
res = req.get("/", :lint => true)
|
|
46
|
+
res.should.be.not_found
|
|
47
|
+
|
|
48
|
+
res.body.should == "foo!"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
should "pass on original headers" do
|
|
52
|
+
headers = {"WWW-Authenticate" => "Basic blah"}
|
|
53
|
+
|
|
54
|
+
req = Rack::MockRequest.new(
|
|
55
|
+
Rack::ShowStatus.new(lambda{|env| [401, headers, []] }))
|
|
56
|
+
res = req.get("/", :lint => true)
|
|
57
|
+
|
|
58
|
+
res["WWW-Authenticate"].should.equal("Basic blah")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
should "replace existing messages if there is detail" do
|
|
62
|
+
req = Rack::MockRequest.new(
|
|
63
|
+
Rack::ShowStatus.new(
|
|
64
|
+
lambda{|env|
|
|
65
|
+
env["rack.showstatus.detail"] = "gone too meta."
|
|
66
|
+
[404, {"Content-Type" => "text/plain", "Content-Length" => "4"}, ["foo!"]]
|
|
67
|
+
}))
|
|
68
|
+
|
|
69
|
+
res = req.get("/", :lint => true)
|
|
70
|
+
res.should.be.not_found
|
|
71
|
+
res.should.be.not.empty
|
|
72
|
+
|
|
73
|
+
res["Content-Type"].should.equal("text/html")
|
|
74
|
+
res["Content-Length"].should.not.equal("4")
|
|
75
|
+
res.should =~ /404/
|
|
76
|
+
res.should =~ /too meta/
|
|
77
|
+
res.body.should.not =~ /foo/
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
require 'test/spec'
|
|
2
|
-
|
|
3
1
|
require 'rack/static'
|
|
4
2
|
require 'rack/mock'
|
|
5
3
|
|
|
@@ -9,26 +7,24 @@ class DummyApp
|
|
|
9
7
|
end
|
|
10
8
|
end
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
describe Rack::Static do
|
|
13
11
|
root = File.expand_path(File.dirname(__FILE__))
|
|
14
12
|
OPTIONS = {:urls => ["/cgi"], :root => root}
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
@request = Rack::MockRequest.new(Rack::Static.new(DummyApp.new, OPTIONS))
|
|
18
|
-
end
|
|
14
|
+
@request = Rack::MockRequest.new(Rack::Static.new(DummyApp.new, OPTIONS))
|
|
19
15
|
|
|
20
|
-
|
|
16
|
+
it "serves files" do
|
|
21
17
|
res = @request.get("/cgi/test")
|
|
22
18
|
res.should.be.ok
|
|
23
19
|
res.body.should =~ /ruby/
|
|
24
20
|
end
|
|
25
21
|
|
|
26
|
-
|
|
22
|
+
it "404s if url root is known but it can't find the file" do
|
|
27
23
|
res = @request.get("/cgi/foo")
|
|
28
24
|
res.should.be.not_found
|
|
29
25
|
end
|
|
30
26
|
|
|
31
|
-
|
|
27
|
+
it "calls down the chain if url root is not known" do
|
|
32
28
|
res = @request.get("/something/else")
|
|
33
29
|
res.should.be.ok
|
|
34
30
|
res.body.should == "Hello World"
|
|
@@ -1,34 +1,31 @@
|
|
|
1
|
-
require 'test/spec'
|
|
2
|
-
|
|
3
1
|
begin
|
|
4
2
|
require 'rack/handler/thin'
|
|
5
|
-
require 'testrequest'
|
|
3
|
+
require File.expand_path('../testrequest', __FILE__)
|
|
6
4
|
require 'timeout'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
end
|
|
5
|
+
|
|
6
|
+
describe Rack::Handler::Thin do
|
|
7
|
+
extend TestRequest::Helpers
|
|
8
|
+
|
|
9
|
+
@app = Rack::Lint.new(TestRequest.new)
|
|
10
|
+
@server = nil
|
|
11
|
+
Thin::Logging.silent = true
|
|
12
|
+
|
|
13
|
+
@thread = Thread.new do
|
|
14
|
+
Rack::Handler::Thin.run(@app, :Host => @host='0.0.0.0', :Port => @port=9204) do |server|
|
|
15
|
+
@server = server
|
|
19
16
|
end
|
|
20
|
-
Thread.pass until @server && @server.running?
|
|
21
17
|
end
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
Thread.pass until @server && @server.running?
|
|
20
|
+
|
|
21
|
+
should "respond" do
|
|
22
|
+
GET("/")
|
|
23
|
+
response.should.not.be.nil
|
|
27
24
|
end
|
|
28
25
|
|
|
29
|
-
|
|
26
|
+
should "be a Thin" do
|
|
30
27
|
GET("/")
|
|
31
|
-
status.should.
|
|
28
|
+
status.should.equal 200
|
|
32
29
|
response["SERVER_SOFTWARE"].should =~ /thin/
|
|
33
30
|
response["HTTP_VERSION"].should.equal "HTTP/1.1"
|
|
34
31
|
response["SERVER_PROTOCOL"].should.equal "HTTP/1.1"
|
|
@@ -36,15 +33,15 @@ context "Rack::Handler::Thin" do
|
|
|
36
33
|
response["SERVER_NAME"].should.equal "0.0.0.0"
|
|
37
34
|
end
|
|
38
35
|
|
|
39
|
-
|
|
36
|
+
should "have rack headers" do
|
|
40
37
|
GET("/")
|
|
41
|
-
response["rack.version"].should.equal [0
|
|
42
|
-
response["rack.multithread"].should.
|
|
43
|
-
response["rack.multiprocess"].should.
|
|
44
|
-
response["rack.run_once"].should.
|
|
38
|
+
response["rack.version"].should.equal [1,0]
|
|
39
|
+
response["rack.multithread"].should.equal false
|
|
40
|
+
response["rack.multiprocess"].should.equal false
|
|
41
|
+
response["rack.run_once"].should.equal false
|
|
45
42
|
end
|
|
46
43
|
|
|
47
|
-
|
|
44
|
+
should "have CGI headers on GET" do
|
|
48
45
|
GET("/")
|
|
49
46
|
response["REQUEST_METHOD"].should.equal "GET"
|
|
50
47
|
response["REQUEST_PATH"].should.equal "/"
|
|
@@ -59,7 +56,7 @@ context "Rack::Handler::Thin" do
|
|
|
59
56
|
response["QUERY_STRING"].should.equal "quux=1"
|
|
60
57
|
end
|
|
61
58
|
|
|
62
|
-
|
|
59
|
+
should "have CGI headers on POST" do
|
|
63
60
|
POST("/", {"rack-form-data" => "23"}, {'X-test-header' => '42'})
|
|
64
61
|
status.should.equal 200
|
|
65
62
|
response["REQUEST_METHOD"].should.equal "POST"
|
|
@@ -69,21 +66,19 @@ context "Rack::Handler::Thin" do
|
|
|
69
66
|
response["test.postdata"].should.equal "rack-form-data=23"
|
|
70
67
|
end
|
|
71
68
|
|
|
72
|
-
|
|
69
|
+
should "support HTTP auth" do
|
|
73
70
|
GET("/test", {:user => "ruth", :passwd => "secret"})
|
|
74
71
|
response["HTTP_AUTHORIZATION"].should.equal "Basic cnV0aDpzZWNyZXQ="
|
|
75
72
|
end
|
|
76
73
|
|
|
77
|
-
|
|
74
|
+
should "set status" do
|
|
78
75
|
GET("/test?secret")
|
|
79
76
|
status.should.equal 403
|
|
80
77
|
response["rack.url_scheme"].should.equal "http"
|
|
81
78
|
end
|
|
82
79
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
@thread.kill
|
|
86
|
-
end
|
|
80
|
+
@server.stop!
|
|
81
|
+
@thread.kill
|
|
87
82
|
end
|
|
88
83
|
|
|
89
84
|
rescue LoadError
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
require 'test/spec'
|
|
2
|
-
|
|
3
1
|
require 'rack/urlmap'
|
|
4
2
|
require 'rack/mock'
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
describe Rack::URLMap do
|
|
5
|
+
it "dispatches paths correctly" do
|
|
8
6
|
app = lambda { |env|
|
|
9
7
|
[200, {
|
|
10
8
|
'X-ScriptName' => env['SCRIPT_NAME'],
|
|
@@ -67,7 +65,7 @@ context "Rack::URLMap" do
|
|
|
67
65
|
end
|
|
68
66
|
|
|
69
67
|
|
|
70
|
-
|
|
68
|
+
it "dispatches hosts correctly" do
|
|
71
69
|
map = Rack::URLMap.new("http://foo.org/" => lambda { |env|
|
|
72
70
|
[200,
|
|
73
71
|
{ "Content-Type" => "text/plain",
|
|
@@ -125,7 +123,7 @@ context "Rack::URLMap" do
|
|
|
125
123
|
res["X-Position"].should.equal "default.org"
|
|
126
124
|
end
|
|
127
125
|
|
|
128
|
-
|
|
126
|
+
should "be nestable" do
|
|
129
127
|
map = Rack::URLMap.new("/foo" =>
|
|
130
128
|
Rack::URLMap.new("/bar" =>
|
|
131
129
|
Rack::URLMap.new("/quux" => lambda { |env|
|
|
@@ -147,7 +145,7 @@ context "Rack::URLMap" do
|
|
|
147
145
|
res["X-ScriptName"].should.equal "/foo/bar/quux"
|
|
148
146
|
end
|
|
149
147
|
|
|
150
|
-
|
|
148
|
+
should "route root apps correctly" do
|
|
151
149
|
map = Rack::URLMap.new("/" => lambda { |env|
|
|
152
150
|
[200,
|
|
153
151
|
{ "Content-Type" => "text/plain",
|
|
@@ -189,7 +187,7 @@ context "Rack::URLMap" do
|
|
|
189
187
|
res["X-ScriptName"].should.equal ""
|
|
190
188
|
end
|
|
191
189
|
|
|
192
|
-
|
|
190
|
+
should "not squeeze slashes" do
|
|
193
191
|
map = Rack::URLMap.new("/" => lambda { |env|
|
|
194
192
|
[200,
|
|
195
193
|
{ "Content-Type" => "text/plain",
|