rack 2.0.9.3 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rack might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +681 -0
- data/CONTRIBUTING.md +136 -0
- data/{COPYING → MIT-LICENSE} +4 -2
- data/README.rdoc +152 -162
- data/Rakefile +37 -23
- data/{SPEC → SPEC.rdoc} +35 -10
- data/bin/rackup +1 -0
- data/example/lobster.ru +2 -0
- data/example/protectedlobster.rb +3 -1
- data/example/protectedlobster.ru +2 -0
- data/lib/rack/auth/abstract/handler.rb +3 -1
- data/lib/rack/auth/abstract/request.rb +1 -1
- data/lib/rack/auth/basic.rb +7 -4
- data/lib/rack/auth/digest/md5.rb +13 -11
- data/lib/rack/auth/digest/nonce.rb +6 -3
- data/lib/rack/auth/digest/params.rb +4 -2
- data/lib/rack/auth/digest/request.rb +5 -3
- data/lib/rack/body_proxy.rb +15 -14
- data/lib/rack/builder.rb +116 -23
- data/lib/rack/cascade.rb +28 -12
- data/lib/rack/chunked.rb +68 -20
- data/lib/rack/common_logger.rb +33 -28
- data/lib/rack/conditional_get.rb +20 -16
- data/lib/rack/config.rb +2 -0
- data/lib/rack/content_length.rb +8 -7
- data/lib/rack/content_type.rb +5 -4
- data/lib/rack/core_ext/regexp.rb +14 -0
- data/lib/rack/deflater.rb +59 -34
- data/lib/rack/directory.rb +84 -64
- data/lib/rack/etag.rb +5 -4
- data/lib/rack/events.rb +19 -20
- data/lib/rack/file.rb +4 -173
- data/lib/rack/files.rb +218 -0
- data/lib/rack/handler/cgi.rb +2 -3
- data/lib/rack/handler/fastcgi.rb +4 -4
- data/lib/rack/handler/lsws.rb +3 -3
- data/lib/rack/handler/scgi.rb +9 -8
- data/lib/rack/handler/thin.rb +17 -11
- data/lib/rack/handler/webrick.rb +15 -6
- data/lib/rack/handler.rb +7 -2
- data/lib/rack/head.rb +1 -1
- data/lib/rack/lint.rb +72 -26
- data/lib/rack/lobster.rb +10 -10
- data/lib/rack/lock.rb +2 -1
- data/lib/rack/logger.rb +2 -0
- data/lib/rack/media_type.rb +10 -5
- data/lib/rack/method_override.rb +4 -2
- data/lib/rack/mime.rb +9 -1
- data/lib/rack/mock.rb +97 -20
- data/lib/rack/multipart/generator.rb +17 -13
- data/lib/rack/multipart/parser.rb +58 -73
- data/lib/rack/multipart/uploaded_file.rb +15 -7
- data/lib/rack/multipart.rb +7 -4
- data/lib/rack/null_logger.rb +2 -0
- data/lib/rack/query_parser.rb +53 -28
- data/lib/rack/recursive.rb +7 -5
- data/lib/rack/reloader.rb +8 -4
- data/lib/rack/request.rb +220 -61
- data/lib/rack/response.rb +127 -44
- data/lib/rack/rewindable_input.rb +4 -3
- data/lib/rack/runtime.rb +6 -4
- data/lib/rack/sendfile.rb +13 -9
- data/lib/rack/server.rb +95 -24
- data/lib/rack/session/abstract/id.rb +33 -21
- data/lib/rack/session/cookie.rb +12 -12
- data/lib/rack/session/memcache.rb +4 -93
- data/lib/rack/session/pool.rb +5 -3
- data/lib/rack/show_exceptions.rb +17 -13
- data/lib/rack/show_status.rb +5 -5
- data/lib/rack/static.rb +23 -11
- data/lib/rack/tempfile_reaper.rb +1 -1
- data/lib/rack/urlmap.rb +12 -6
- data/lib/rack/utils.rb +105 -130
- data/lib/rack/version.rb +29 -0
- data/lib/rack.rb +67 -73
- data/rack.gemspec +40 -28
- metadata +39 -182
- data/HISTORY.md +0 -520
- data/test/builder/an_underscore_app.rb +0 -5
- data/test/builder/anything.rb +0 -5
- data/test/builder/comment.ru +0 -4
- data/test/builder/end.ru +0 -5
- data/test/builder/line.ru +0 -1
- data/test/builder/options.ru +0 -2
- data/test/cgi/assets/folder/test.js +0 -1
- data/test/cgi/assets/fonts/font.eot +0 -1
- data/test/cgi/assets/images/image.png +0 -1
- data/test/cgi/assets/index.html +0 -1
- data/test/cgi/assets/javascripts/app.js +0 -1
- data/test/cgi/assets/stylesheets/app.css +0 -1
- data/test/cgi/lighttpd.conf +0 -26
- data/test/cgi/rackup_stub.rb +0 -6
- data/test/cgi/sample_rackup.ru +0 -5
- data/test/cgi/test +0 -9
- data/test/cgi/test+directory/test+file +0 -1
- data/test/cgi/test.fcgi +0 -9
- data/test/cgi/test.gz +0 -0
- data/test/cgi/test.ru +0 -5
- data/test/gemloader.rb +0 -10
- data/test/helper.rb +0 -34
- data/test/multipart/bad_robots +0 -259
- data/test/multipart/binary +0 -0
- data/test/multipart/content_type_and_no_filename +0 -6
- data/test/multipart/empty +0 -10
- data/test/multipart/fail_16384_nofile +0 -814
- data/test/multipart/file1.txt +0 -1
- data/test/multipart/filename_and_modification_param +0 -7
- data/test/multipart/filename_and_no_name +0 -6
- data/test/multipart/filename_with_encoded_words +0 -7
- data/test/multipart/filename_with_escaped_quotes +0 -6
- data/test/multipart/filename_with_escaped_quotes_and_modification_param +0 -7
- data/test/multipart/filename_with_null_byte +0 -7
- data/test/multipart/filename_with_percent_escaped_quotes +0 -6
- data/test/multipart/filename_with_single_quote +0 -7
- data/test/multipart/filename_with_unescaped_percentages +0 -6
- data/test/multipart/filename_with_unescaped_percentages2 +0 -6
- data/test/multipart/filename_with_unescaped_percentages3 +0 -6
- data/test/multipart/filename_with_unescaped_quotes +0 -6
- data/test/multipart/ie +0 -6
- data/test/multipart/invalid_character +0 -6
- data/test/multipart/mixed_files +0 -21
- data/test/multipart/nested +0 -10
- data/test/multipart/none +0 -9
- data/test/multipart/quoted +0 -15
- data/test/multipart/rack-logo.png +0 -0
- data/test/multipart/semicolon +0 -6
- data/test/multipart/text +0 -15
- data/test/multipart/three_files_three_fields +0 -31
- data/test/multipart/unity3d_wwwform +0 -11
- data/test/multipart/webkit +0 -32
- data/test/rackup/config.ru +0 -31
- data/test/registering_handler/rack/handler/registering_myself.rb +0 -8
- data/test/spec_auth_basic.rb +0 -89
- data/test/spec_auth_digest.rb +0 -260
- data/test/spec_body_proxy.rb +0 -85
- data/test/spec_builder.rb +0 -233
- data/test/spec_cascade.rb +0 -63
- data/test/spec_cgi.rb +0 -84
- data/test/spec_chunked.rb +0 -103
- data/test/spec_common_logger.rb +0 -107
- data/test/spec_conditional_get.rb +0 -103
- data/test/spec_config.rb +0 -23
- data/test/spec_content_length.rb +0 -86
- data/test/spec_content_type.rb +0 -46
- data/test/spec_deflater.rb +0 -375
- data/test/spec_directory.rb +0 -148
- data/test/spec_etag.rb +0 -108
- data/test/spec_events.rb +0 -133
- data/test/spec_fastcgi.rb +0 -85
- data/test/spec_file.rb +0 -264
- data/test/spec_handler.rb +0 -57
- data/test/spec_head.rb +0 -46
- data/test/spec_lint.rb +0 -520
- data/test/spec_lobster.rb +0 -59
- data/test/spec_lock.rb +0 -204
- data/test/spec_logger.rb +0 -24
- data/test/spec_media_type.rb +0 -42
- data/test/spec_method_override.rb +0 -110
- data/test/spec_mime.rb +0 -51
- data/test/spec_mock.rb +0 -359
- data/test/spec_multipart.rb +0 -721
- data/test/spec_null_logger.rb +0 -21
- data/test/spec_recursive.rb +0 -75
- data/test/spec_request.rb +0 -1423
- data/test/spec_response.rb +0 -528
- data/test/spec_rewindable_input.rb +0 -128
- data/test/spec_runtime.rb +0 -50
- data/test/spec_sendfile.rb +0 -125
- data/test/spec_server.rb +0 -193
- data/test/spec_session_abstract_id.rb +0 -31
- data/test/spec_session_abstract_session_hash.rb +0 -45
- data/test/spec_session_cookie.rb +0 -442
- data/test/spec_session_memcache.rb +0 -357
- data/test/spec_session_persisted_secure_secure_session_hash.rb +0 -73
- data/test/spec_session_pool.rb +0 -247
- data/test/spec_show_exceptions.rb +0 -93
- data/test/spec_show_status.rb +0 -104
- data/test/spec_static.rb +0 -184
- data/test/spec_tempfile_reaper.rb +0 -64
- data/test/spec_thin.rb +0 -96
- data/test/spec_urlmap.rb +0 -237
- data/test/spec_utils.rb +0 -742
- data/test/spec_version.rb +0 -11
- data/test/spec_webrick.rb +0 -206
- data/test/static/another/index.html +0 -1
- data/test/static/foo.html +0 -1
- data/test/static/index.html +0 -1
- data/test/testrequest.rb +0 -78
- data/test/unregistered_handler/rack/handler/unregistered.rb +0 -7
- data/test/unregistered_handler/rack/handler/unregistered_long_one.rb +0 -7
data/test/spec_directory.rb
DELETED
@@ -1,148 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'rack/directory'
|
3
|
-
require 'rack/lint'
|
4
|
-
require 'rack/mock'
|
5
|
-
require 'tempfile'
|
6
|
-
require 'fileutils'
|
7
|
-
|
8
|
-
describe Rack::Directory do
|
9
|
-
DOCROOT = File.expand_path(File.dirname(__FILE__)) unless defined? DOCROOT
|
10
|
-
FILE_CATCH = proc{|env| [200, {'Content-Type'=>'text/plain', "Content-Length" => "7"}, ['passed!']] }
|
11
|
-
|
12
|
-
attr_reader :app
|
13
|
-
|
14
|
-
def setup
|
15
|
-
@app = Rack::Lint.new(Rack::Directory.new(DOCROOT, FILE_CATCH))
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'serves directories with + in the name' do
|
19
|
-
Dir.mktmpdir do |dir|
|
20
|
-
plus_dir = "foo+bar"
|
21
|
-
full_dir = File.join(dir, plus_dir)
|
22
|
-
FileUtils.mkdir full_dir
|
23
|
-
FileUtils.touch File.join(full_dir, "omg.txt")
|
24
|
-
app = Rack::Directory.new(dir, FILE_CATCH)
|
25
|
-
env = Rack::MockRequest.env_for("/#{plus_dir}/")
|
26
|
-
status,_,body = app.call env
|
27
|
-
|
28
|
-
assert_equal 200, status
|
29
|
-
|
30
|
-
str = ''
|
31
|
-
body.each { |x| str << x }
|
32
|
-
assert_match "foo+bar", str
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it "serve directory indices" do
|
37
|
-
res = Rack::MockRequest.new(Rack::Lint.new(app)).
|
38
|
-
get("/cgi/")
|
39
|
-
|
40
|
-
res.must_be :ok?
|
41
|
-
assert_match(res, /<html><head>/)
|
42
|
-
end
|
43
|
-
|
44
|
-
it "pass to app if file found" do
|
45
|
-
res = Rack::MockRequest.new(Rack::Lint.new(app)).
|
46
|
-
get("/cgi/test")
|
47
|
-
|
48
|
-
res.must_be :ok?
|
49
|
-
assert_match(res, /passed!/)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "serve uri with URL encoded filenames" do
|
53
|
-
res = Rack::MockRequest.new(Rack::Lint.new(app)).
|
54
|
-
get("/%63%67%69/") # "/cgi/test"
|
55
|
-
|
56
|
-
res.must_be :ok?
|
57
|
-
assert_match(res, /<html><head>/)
|
58
|
-
|
59
|
-
res = Rack::MockRequest.new(Rack::Lint.new(app)).
|
60
|
-
get("/cgi/%74%65%73%74") # "/cgi/test"
|
61
|
-
|
62
|
-
res.must_be :ok?
|
63
|
-
assert_match(res, /passed!/)
|
64
|
-
end
|
65
|
-
|
66
|
-
it "serve uri with URL encoded null byte (%00) in filenames" do
|
67
|
-
res = Rack::MockRequest.new(Rack::Lint.new(app))
|
68
|
-
.get("/cgi/test%00")
|
69
|
-
|
70
|
-
res.must_be :bad_request?
|
71
|
-
end
|
72
|
-
|
73
|
-
it "not allow directory traversal" do
|
74
|
-
res = Rack::MockRequest.new(Rack::Lint.new(app)).
|
75
|
-
get("/cgi/../test")
|
76
|
-
|
77
|
-
res.must_be :forbidden?
|
78
|
-
|
79
|
-
res = Rack::MockRequest.new(Rack::Lint.new(app)).
|
80
|
-
get("/cgi/%2E%2E/test")
|
81
|
-
|
82
|
-
res.must_be :forbidden?
|
83
|
-
end
|
84
|
-
|
85
|
-
it "404 if it can't find the file" do
|
86
|
-
res = Rack::MockRequest.new(Rack::Lint.new(app)).
|
87
|
-
get("/cgi/blubb")
|
88
|
-
|
89
|
-
res.must_be :not_found?
|
90
|
-
end
|
91
|
-
|
92
|
-
it "uri escape path parts" do # #265, properly escape file names
|
93
|
-
mr = Rack::MockRequest.new(Rack::Lint.new(app))
|
94
|
-
|
95
|
-
res = mr.get("/cgi/test%2bdirectory")
|
96
|
-
|
97
|
-
res.must_be :ok?
|
98
|
-
res.body.must_match(%r[/cgi/test\+directory/test\+file])
|
99
|
-
|
100
|
-
res = mr.get("/cgi/test%2bdirectory/test%2bfile")
|
101
|
-
res.must_be :ok?
|
102
|
-
end
|
103
|
-
|
104
|
-
it "correctly escape script name with spaces" do
|
105
|
-
Dir.mktmpdir do |dir|
|
106
|
-
space_dir = "foo bar"
|
107
|
-
full_dir = File.join(dir, space_dir)
|
108
|
-
FileUtils.mkdir full_dir
|
109
|
-
FileUtils.touch File.join(full_dir, "omg omg.txt")
|
110
|
-
app = Rack::Directory.new(dir, FILE_CATCH)
|
111
|
-
env = Rack::MockRequest.env_for(Rack::Utils.escape_path("/#{space_dir}/"))
|
112
|
-
status,_,body = app.call env
|
113
|
-
|
114
|
-
assert_equal 200, status
|
115
|
-
|
116
|
-
str = ''
|
117
|
-
body.each { |x| str << x }
|
118
|
-
assert_match "/foo%20bar/omg%20omg.txt", str
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
it "correctly escape script name" do
|
123
|
-
_app = app
|
124
|
-
app2 = Rack::Builder.new do
|
125
|
-
map '/script-path' do
|
126
|
-
run _app
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
mr = Rack::MockRequest.new(Rack::Lint.new(app2))
|
131
|
-
|
132
|
-
res = mr.get("/script-path/cgi/test%2bdirectory")
|
133
|
-
|
134
|
-
res.must_be :ok?
|
135
|
-
res.body.must_match(%r[/script-path/cgi/test\+directory/test\+file])
|
136
|
-
|
137
|
-
res = mr.get("/script-path/cgi/test+directory/test+file")
|
138
|
-
res.must_be :ok?
|
139
|
-
end
|
140
|
-
|
141
|
-
it "return error when file not found for head request" do
|
142
|
-
res = Rack::MockRequest.new(Rack::Lint.new(app)).
|
143
|
-
head("/cgi/missing")
|
144
|
-
|
145
|
-
res.must_be :not_found?
|
146
|
-
res.body.must_be :empty?
|
147
|
-
end
|
148
|
-
end
|
data/test/spec_etag.rb
DELETED
@@ -1,108 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'rack/etag'
|
3
|
-
require 'rack/lint'
|
4
|
-
require 'rack/mock'
|
5
|
-
require 'time'
|
6
|
-
|
7
|
-
describe Rack::ETag do
|
8
|
-
def etag(app, *args)
|
9
|
-
Rack::Lint.new Rack::ETag.new(app, *args)
|
10
|
-
end
|
11
|
-
|
12
|
-
def request
|
13
|
-
Rack::MockRequest.env_for
|
14
|
-
end
|
15
|
-
|
16
|
-
def sendfile_body
|
17
|
-
res = ['Hello World']
|
18
|
-
def res.to_path ; "/tmp/hello.txt" ; end
|
19
|
-
res
|
20
|
-
end
|
21
|
-
|
22
|
-
it "set ETag if none is set if status is 200" do
|
23
|
-
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]] }
|
24
|
-
response = etag(app).call(request)
|
25
|
-
response[1]['ETag'].must_equal "W/\"dffd6021bb2bd5b0af676290809ec3a5\""
|
26
|
-
end
|
27
|
-
|
28
|
-
it "set ETag if none is set if status is 201" do
|
29
|
-
app = lambda { |env| [201, {'Content-Type' => 'text/plain'}, ["Hello, World!"]] }
|
30
|
-
response = etag(app).call(request)
|
31
|
-
response[1]['ETag'].must_equal "W/\"dffd6021bb2bd5b0af676290809ec3a5\""
|
32
|
-
end
|
33
|
-
|
34
|
-
it "set Cache-Control to 'max-age=0, private, must-revalidate' (default) if none is set" do
|
35
|
-
app = lambda { |env| [201, {'Content-Type' => 'text/plain'}, ["Hello, World!"]] }
|
36
|
-
response = etag(app).call(request)
|
37
|
-
response[1]['Cache-Control'].must_equal 'max-age=0, private, must-revalidate'
|
38
|
-
end
|
39
|
-
|
40
|
-
it "set Cache-Control to chosen one if none is set" do
|
41
|
-
app = lambda { |env| [201, {'Content-Type' => 'text/plain'}, ["Hello, World!"]] }
|
42
|
-
response = etag(app, nil, 'public').call(request)
|
43
|
-
response[1]['Cache-Control'].must_equal 'public'
|
44
|
-
end
|
45
|
-
|
46
|
-
it "set a given Cache-Control even if digest could not be calculated" do
|
47
|
-
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, []] }
|
48
|
-
response = etag(app, 'no-cache').call(request)
|
49
|
-
response[1]['Cache-Control'].must_equal 'no-cache'
|
50
|
-
end
|
51
|
-
|
52
|
-
it "not set Cache-Control if it is already set" do
|
53
|
-
app = lambda { |env| [201, {'Content-Type' => 'text/plain', 'Cache-Control' => 'public'}, ["Hello, World!"]] }
|
54
|
-
response = etag(app).call(request)
|
55
|
-
response[1]['Cache-Control'].must_equal 'public'
|
56
|
-
end
|
57
|
-
|
58
|
-
it "not set Cache-Control if directive isn't present" do
|
59
|
-
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]] }
|
60
|
-
response = etag(app, nil, nil).call(request)
|
61
|
-
response[1]['Cache-Control'].must_be_nil
|
62
|
-
end
|
63
|
-
|
64
|
-
it "not change ETag if it is already set" do
|
65
|
-
app = lambda { |env| [200, {'Content-Type' => 'text/plain', 'ETag' => '"abc"'}, ["Hello, World!"]] }
|
66
|
-
response = etag(app).call(request)
|
67
|
-
response[1]['ETag'].must_equal "\"abc\""
|
68
|
-
end
|
69
|
-
|
70
|
-
it "not set ETag if body is empty" do
|
71
|
-
app = lambda { |env| [200, {'Content-Type' => 'text/plain', 'Last-Modified' => Time.now.httpdate}, []] }
|
72
|
-
response = etag(app).call(request)
|
73
|
-
response[1]['ETag'].must_be_nil
|
74
|
-
end
|
75
|
-
|
76
|
-
it "not set ETag if Last-Modified is set" do
|
77
|
-
app = lambda { |env| [200, {'Content-Type' => 'text/plain', 'Last-Modified' => Time.now.httpdate}, ["Hello, World!"]] }
|
78
|
-
response = etag(app).call(request)
|
79
|
-
response[1]['ETag'].must_be_nil
|
80
|
-
end
|
81
|
-
|
82
|
-
it "not set ETag if a sendfile_body is given" do
|
83
|
-
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, sendfile_body] }
|
84
|
-
response = etag(app).call(request)
|
85
|
-
response[1]['ETag'].must_be_nil
|
86
|
-
end
|
87
|
-
|
88
|
-
it "not set ETag if a status is not 200 or 201" do
|
89
|
-
app = lambda { |env| [401, {'Content-Type' => 'text/plain'}, ['Access denied.']] }
|
90
|
-
response = etag(app).call(request)
|
91
|
-
response[1]['ETag'].must_be_nil
|
92
|
-
end
|
93
|
-
|
94
|
-
it "not set ETag if no-cache is given" do
|
95
|
-
app = lambda { |env| [200, {'Content-Type' => 'text/plain', 'Cache-Control' => 'no-cache, must-revalidate'}, ['Hello, World!']] }
|
96
|
-
response = etag(app).call(request)
|
97
|
-
response[1]['ETag'].must_be_nil
|
98
|
-
end
|
99
|
-
|
100
|
-
it "close the original body" do
|
101
|
-
body = StringIO.new
|
102
|
-
app = lambda { |env| [200, {}, body] }
|
103
|
-
response = etag(app).call(request)
|
104
|
-
body.wont_be :closed?
|
105
|
-
response[2].close
|
106
|
-
body.must_be :closed?
|
107
|
-
end
|
108
|
-
end
|
data/test/spec_events.rb
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
require 'rack/events'
|
3
|
-
|
4
|
-
module Rack
|
5
|
-
class TestEvents < Rack::TestCase
|
6
|
-
class EventMiddleware
|
7
|
-
attr_reader :events
|
8
|
-
|
9
|
-
def initialize events
|
10
|
-
@events = events
|
11
|
-
end
|
12
|
-
|
13
|
-
def on_start req, res
|
14
|
-
events << [self, __method__]
|
15
|
-
end
|
16
|
-
|
17
|
-
def on_commit req, res
|
18
|
-
events << [self, __method__]
|
19
|
-
end
|
20
|
-
|
21
|
-
def on_send req, res
|
22
|
-
events << [self, __method__]
|
23
|
-
end
|
24
|
-
|
25
|
-
def on_finish req, res
|
26
|
-
events << [self, __method__]
|
27
|
-
end
|
28
|
-
|
29
|
-
def on_error req, res, e
|
30
|
-
events << [self, __method__]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_events_fire
|
35
|
-
events = []
|
36
|
-
ret = [200, {}, []]
|
37
|
-
app = lambda { |env| events << [app, :call]; ret }
|
38
|
-
se = EventMiddleware.new events
|
39
|
-
e = Events.new app, [se]
|
40
|
-
triple = e.call({})
|
41
|
-
response_body = []
|
42
|
-
triple[2].each { |x| response_body << x }
|
43
|
-
triple[2].close
|
44
|
-
triple[2] = response_body
|
45
|
-
assert_equal ret, triple
|
46
|
-
assert_equal [[se, :on_start],
|
47
|
-
[app, :call],
|
48
|
-
[se, :on_commit],
|
49
|
-
[se, :on_send],
|
50
|
-
[se, :on_finish],
|
51
|
-
], events
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_send_and_finish_are_not_run_until_body_is_sent
|
55
|
-
events = []
|
56
|
-
ret = [200, {}, []]
|
57
|
-
app = lambda { |env| events << [app, :call]; ret }
|
58
|
-
se = EventMiddleware.new events
|
59
|
-
e = Events.new app, [se]
|
60
|
-
triple = e.call({})
|
61
|
-
assert_equal [[se, :on_start],
|
62
|
-
[app, :call],
|
63
|
-
[se, :on_commit],
|
64
|
-
], events
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_send_is_called_on_each
|
68
|
-
events = []
|
69
|
-
ret = [200, {}, []]
|
70
|
-
app = lambda { |env| events << [app, :call]; ret }
|
71
|
-
se = EventMiddleware.new events
|
72
|
-
e = Events.new app, [se]
|
73
|
-
triple = e.call({})
|
74
|
-
triple[2].each { |x| }
|
75
|
-
assert_equal [[se, :on_start],
|
76
|
-
[app, :call],
|
77
|
-
[se, :on_commit],
|
78
|
-
[se, :on_send],
|
79
|
-
], events
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_finish_is_called_on_close
|
83
|
-
events = []
|
84
|
-
ret = [200, {}, []]
|
85
|
-
app = lambda { |env| events << [app, :call]; ret }
|
86
|
-
se = EventMiddleware.new events
|
87
|
-
e = Events.new app, [se]
|
88
|
-
triple = e.call({})
|
89
|
-
triple[2].each { |x| }
|
90
|
-
triple[2].close
|
91
|
-
assert_equal [[se, :on_start],
|
92
|
-
[app, :call],
|
93
|
-
[se, :on_commit],
|
94
|
-
[se, :on_send],
|
95
|
-
[se, :on_finish],
|
96
|
-
], events
|
97
|
-
end
|
98
|
-
|
99
|
-
def test_finish_is_called_in_reverse_order
|
100
|
-
events = []
|
101
|
-
ret = [200, {}, []]
|
102
|
-
app = lambda { |env| events << [app, :call]; ret }
|
103
|
-
se1 = EventMiddleware.new events
|
104
|
-
se2 = EventMiddleware.new events
|
105
|
-
se3 = EventMiddleware.new events
|
106
|
-
|
107
|
-
e = Events.new app, [se1, se2, se3]
|
108
|
-
triple = e.call({})
|
109
|
-
triple[2].each { |x| }
|
110
|
-
triple[2].close
|
111
|
-
|
112
|
-
groups = events.group_by { |x| x.last }
|
113
|
-
assert_equal groups[:on_start].map(&:first), groups[:on_finish].map(&:first).reverse
|
114
|
-
assert_equal groups[:on_commit].map(&:first), groups[:on_finish].map(&:first)
|
115
|
-
assert_equal groups[:on_send].map(&:first), groups[:on_finish].map(&:first)
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_finish_is_called_if_there_is_an_exception
|
119
|
-
events = []
|
120
|
-
ret = [200, {}, []]
|
121
|
-
app = lambda { |env| raise }
|
122
|
-
se = EventMiddleware.new events
|
123
|
-
e = Events.new app, [se]
|
124
|
-
assert_raises(RuntimeError) do
|
125
|
-
e.call({})
|
126
|
-
end
|
127
|
-
assert_equal [[se, :on_start],
|
128
|
-
[se, :on_error],
|
129
|
-
[se, :on_finish],
|
130
|
-
], events
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
data/test/spec_fastcgi.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
if defined? LIGHTTPD_PID
|
4
|
-
|
5
|
-
require File.expand_path('../testrequest', __FILE__)
|
6
|
-
require 'rack/handler/fastcgi'
|
7
|
-
|
8
|
-
describe Rack::Handler::FastCGI do
|
9
|
-
include TestRequest::Helpers
|
10
|
-
|
11
|
-
before do
|
12
|
-
@host = '127.0.0.1'
|
13
|
-
@port = 9203
|
14
|
-
end
|
15
|
-
|
16
|
-
it "respond" do
|
17
|
-
sleep 1
|
18
|
-
GET("/test")
|
19
|
-
response.wont_be :nil?
|
20
|
-
end
|
21
|
-
|
22
|
-
it "respond via rackup server" do
|
23
|
-
GET("/sample_rackup.ru")
|
24
|
-
status.must_equal 200
|
25
|
-
end
|
26
|
-
|
27
|
-
it "be a lighttpd" do
|
28
|
-
GET("/test.fcgi")
|
29
|
-
status.must_equal 200
|
30
|
-
response["SERVER_SOFTWARE"].must_match(/lighttpd/)
|
31
|
-
response["HTTP_VERSION"].must_equal "HTTP/1.1"
|
32
|
-
response["SERVER_PROTOCOL"].must_equal "HTTP/1.1"
|
33
|
-
response["SERVER_PORT"].must_equal @port.to_s
|
34
|
-
response["SERVER_NAME"].must_equal @host
|
35
|
-
end
|
36
|
-
|
37
|
-
it "have rack headers" do
|
38
|
-
GET("/test.fcgi")
|
39
|
-
response["rack.version"].must_equal [1,3]
|
40
|
-
assert_equal false, response["rack.multithread"]
|
41
|
-
assert_equal true, response["rack.multiprocess"]
|
42
|
-
assert_equal false, response["rack.run_once"]
|
43
|
-
end
|
44
|
-
|
45
|
-
it "have CGI headers on GET" do
|
46
|
-
GET("/test.fcgi")
|
47
|
-
response["REQUEST_METHOD"].must_equal "GET"
|
48
|
-
response["SCRIPT_NAME"].must_equal "/test.fcgi"
|
49
|
-
response["REQUEST_PATH"].must_equal "/"
|
50
|
-
response["PATH_INFO"].must_equal ""
|
51
|
-
response["QUERY_STRING"].must_equal ""
|
52
|
-
response["test.postdata"].must_equal ""
|
53
|
-
|
54
|
-
GET("/test.fcgi/foo?quux=1")
|
55
|
-
response["REQUEST_METHOD"].must_equal "GET"
|
56
|
-
response["SCRIPT_NAME"].must_equal "/test.fcgi"
|
57
|
-
response["REQUEST_PATH"].must_equal "/"
|
58
|
-
response["PATH_INFO"].must_equal "/foo"
|
59
|
-
response["QUERY_STRING"].must_equal "quux=1"
|
60
|
-
end
|
61
|
-
|
62
|
-
it "have CGI headers on POST" do
|
63
|
-
POST("/test.fcgi", {"rack-form-data" => "23"}, {'X-test-header' => '42'})
|
64
|
-
status.must_equal 200
|
65
|
-
response["REQUEST_METHOD"].must_equal "POST"
|
66
|
-
response["SCRIPT_NAME"].must_equal "/test.fcgi"
|
67
|
-
response["REQUEST_PATH"].must_equal "/"
|
68
|
-
response["QUERY_STRING"].must_equal ""
|
69
|
-
response["HTTP_X_TEST_HEADER"].must_equal "42"
|
70
|
-
response["test.postdata"].must_equal "rack-form-data=23"
|
71
|
-
end
|
72
|
-
|
73
|
-
it "support HTTP auth" do
|
74
|
-
GET("/test.fcgi", {:user => "ruth", :passwd => "secret"})
|
75
|
-
response["HTTP_AUTHORIZATION"].must_equal "Basic cnV0aDpzZWNyZXQ="
|
76
|
-
end
|
77
|
-
|
78
|
-
it "set status" do
|
79
|
-
GET("/test.fcgi?secret")
|
80
|
-
status.must_equal 403
|
81
|
-
response["rack.url_scheme"].must_equal "http"
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
end # if defined? LIGHTTPD_PID
|