rack-contrib 1.2.0 → 1.2.0.39.g17d21b4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rack-contrib might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/README.md +98 -0
- data/lib/rack/contrib.rb +3 -1
- data/lib/rack/contrib/enforce_valid_encoding.rb +23 -0
- data/lib/rack/contrib/jsonp.rb +5 -1
- data/lib/rack/contrib/locale.rb +1 -1
- data/lib/rack/contrib/mailexceptions.rb +41 -10
- data/lib/rack/contrib/post_body_content_type_parser.rb +1 -1
- data/lib/rack/contrib/relative_redirect.rb +1 -1
- data/lib/rack/contrib/try_static.rb +1 -1
- metadata +166 -113
- data/README.rdoc +0 -98
- data/Rakefile +0 -89
- data/rack-contrib.gemspec +0 -112
- data/test/404.html +0 -1
- data/test/Maintenance.html +0 -1
- data/test/documents/existing.html +0 -1
- data/test/documents/index.htm +0 -1
- data/test/documents/index.html +0 -1
- data/test/documents/test +0 -1
- data/test/mail_settings.rb +0 -20
- data/test/spec_rack_accept_format.rb +0 -72
- data/test/spec_rack_access.rb +0 -154
- data/test/spec_rack_backstage.rb +0 -26
- data/test/spec_rack_callbacks.rb +0 -65
- data/test/spec_rack_common_cookies.rb +0 -107
- data/test/spec_rack_config.rb +0 -22
- data/test/spec_rack_contrib.rb +0 -8
- data/test/spec_rack_cookies.rb +0 -56
- data/test/spec_rack_csshttprequest.rb +0 -66
- data/test/spec_rack_deflect.rb +0 -107
- data/test/spec_rack_evil.rb +0 -19
- data/test/spec_rack_expectation_cascade.rb +0 -72
- data/test/spec_rack_garbagecollector.rb +0 -13
- data/test/spec_rack_host_meta.rb +0 -50
- data/test/spec_rack_jsonp.rb +0 -188
- data/test/spec_rack_lighttpd_script_name_fix.rb +0 -16
- data/test/spec_rack_mailexceptions.rb +0 -169
- data/test/spec_rack_nested_params.rb +0 -46
- data/test/spec_rack_not_found.rb +0 -17
- data/test/spec_rack_post_body_content_type_parser.rb +0 -40
- data/test/spec_rack_proctitle.rb +0 -26
- data/test/spec_rack_profiler.rb +0 -42
- data/test/spec_rack_relative_redirect.rb +0 -78
- data/test/spec_rack_response_cache.rb +0 -137
- data/test/spec_rack_response_headers.rb +0 -35
- data/test/spec_rack_runtime.rb +0 -35
- data/test/spec_rack_sendfile.rb +0 -86
- data/test/spec_rack_simple_endpoint.rb +0 -95
- data/test/spec_rack_static_cache.rb +0 -104
- data/test/spec_rack_try_static.rb +0 -56
- data/test/statics/test +0 -1
data/test/spec_rack_sendfile.rb
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
require 'test/spec'
|
2
|
-
require 'rack/mock'
|
3
|
-
require 'rack/contrib/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,95 +0,0 @@
|
|
1
|
-
require 'test/spec'
|
2
|
-
require 'rack'
|
3
|
-
require 'rack/contrib/simple_endpoint'
|
4
|
-
|
5
|
-
context "Rack::SimpleEndpoint" do
|
6
|
-
setup do
|
7
|
-
@app = Proc.new { Rack::Response.new {|r| r.write "Downstream app"}.finish }
|
8
|
-
end
|
9
|
-
|
10
|
-
specify "calls downstream app when no match" do
|
11
|
-
endpoint = Rack::SimpleEndpoint.new(@app, '/foo') { 'bar' }
|
12
|
-
status, headers, body = endpoint.call(Rack::MockRequest.env_for('/baz'))
|
13
|
-
status.should == 200
|
14
|
-
body.body.should == ['Downstream app']
|
15
|
-
end
|
16
|
-
|
17
|
-
specify "calls downstream app when path matches but method does not" do
|
18
|
-
endpoint = Rack::SimpleEndpoint.new(@app, '/foo' => :get) { 'bar' }
|
19
|
-
status, headers, body = endpoint.call(Rack::MockRequest.env_for('/foo', :method => 'post'))
|
20
|
-
status.should == 200
|
21
|
-
body.body.should == ['Downstream app']
|
22
|
-
end
|
23
|
-
|
24
|
-
specify "calls downstream app when path matches but block returns :pass" do
|
25
|
-
endpoint = Rack::SimpleEndpoint.new(@app, '/foo') { :pass }
|
26
|
-
status, headers, body = endpoint.call(Rack::MockRequest.env_for('/foo'))
|
27
|
-
status.should == 200
|
28
|
-
body.body.should == ['Downstream app']
|
29
|
-
end
|
30
|
-
|
31
|
-
specify "returns endpoint response when path matches" do
|
32
|
-
endpoint = Rack::SimpleEndpoint.new(@app, '/foo') { 'bar' }
|
33
|
-
status, headers, body = endpoint.call(Rack::MockRequest.env_for('/foo'))
|
34
|
-
status.should == 200
|
35
|
-
body.body.should == ['bar']
|
36
|
-
end
|
37
|
-
|
38
|
-
specify "returns endpoint response when path and single method requirement match" do
|
39
|
-
endpoint = Rack::SimpleEndpoint.new(@app, '/foo' => :get) { 'bar' }
|
40
|
-
status, headers, body = endpoint.call(Rack::MockRequest.env_for('/foo'))
|
41
|
-
status.should == 200
|
42
|
-
body.body.should == ['bar']
|
43
|
-
end
|
44
|
-
|
45
|
-
specify "returns endpoint response when path and one of multiple method requirements match" do
|
46
|
-
endpoint = Rack::SimpleEndpoint.new(@app, '/foo' => [:get, :post]) { 'bar' }
|
47
|
-
status, headers, body = endpoint.call(Rack::MockRequest.env_for('/foo', :method => 'post'))
|
48
|
-
status.should == 200
|
49
|
-
body.body.should == ['bar']
|
50
|
-
end
|
51
|
-
|
52
|
-
specify "returns endpoint response when path matches regex" do
|
53
|
-
endpoint = Rack::SimpleEndpoint.new(@app, /foo/) { 'bar' }
|
54
|
-
status, headers, body = endpoint.call(Rack::MockRequest.env_for('/bar/foo'))
|
55
|
-
status.should == 200
|
56
|
-
body.body.should == ['bar']
|
57
|
-
end
|
58
|
-
|
59
|
-
specify "block yields Rack::Request and Rack::Response objects" do
|
60
|
-
endpoint = Rack::SimpleEndpoint.new(@app, '/foo') do |req, res|
|
61
|
-
assert_instance_of ::Rack::Request, req
|
62
|
-
assert_instance_of ::Rack::Response, res
|
63
|
-
end
|
64
|
-
endpoint.call(Rack::MockRequest.env_for('/foo'))
|
65
|
-
end
|
66
|
-
|
67
|
-
specify "block yields MatchData object when Regex path matcher specified" do
|
68
|
-
endpoint = Rack::SimpleEndpoint.new(@app, /foo(.+)/) do |req, res, match|
|
69
|
-
assert_instance_of MatchData, match
|
70
|
-
assert_equal 'bar', match[1]
|
71
|
-
end
|
72
|
-
endpoint.call(Rack::MockRequest.env_for('/foobar'))
|
73
|
-
end
|
74
|
-
|
75
|
-
specify "block does NOT yield MatchData object when String path matcher specified" do
|
76
|
-
endpoint = Rack::SimpleEndpoint.new(@app, '/foo') do |req, res, match|
|
77
|
-
assert_nil match
|
78
|
-
end
|
79
|
-
endpoint.call(Rack::MockRequest.env_for('/foo'))
|
80
|
-
end
|
81
|
-
|
82
|
-
specify "response honors headers set in block" do
|
83
|
-
endpoint = Rack::SimpleEndpoint.new(@app, '/foo') {|req, res| res['X-Foo'] = 'bar'; 'baz' }
|
84
|
-
status, headers, body = endpoint.call(Rack::MockRequest.env_for('/foo'))
|
85
|
-
status.should == 200
|
86
|
-
headers['X-Foo'].should == 'bar'
|
87
|
-
body.body.should == ['baz']
|
88
|
-
end
|
89
|
-
|
90
|
-
specify "sets Content-Length header" do
|
91
|
-
endpoint = Rack::SimpleEndpoint.new(@app, '/foo') {|req, res| 'bar' }
|
92
|
-
status, headers, body = endpoint.call(Rack::MockRequest.env_for('/foo'))
|
93
|
-
headers['Content-Length'].should == '3'
|
94
|
-
end
|
95
|
-
end
|
@@ -1,104 +0,0 @@
|
|
1
|
-
require 'test/spec'
|
2
|
-
|
3
|
-
require 'rack'
|
4
|
-
require 'rack/contrib/static_cache'
|
5
|
-
require 'rack/mock'
|
6
|
-
|
7
|
-
class DummyApp
|
8
|
-
def call(env)
|
9
|
-
[200, {}, ["Hello World"]]
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "Rack::StaticCache" do
|
14
|
-
|
15
|
-
setup do
|
16
|
-
@root = ::File.expand_path(::File.dirname(__FILE__))
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should serve files with required headers" do
|
20
|
-
default_app_request
|
21
|
-
res = @request.get("/statics/test")
|
22
|
-
res.should.be.ok
|
23
|
-
res.body.should =~ /rubyrack/
|
24
|
-
res.headers['Cache-Control'].should == 'max-age=31536000, public'
|
25
|
-
next_year = Time.now().year + 1
|
26
|
-
res.headers['Expires'].should =~ Regexp.new(
|
27
|
-
"[A-Z][a-z]{2}[,][\s][0-9]{2}[\s][A-Z][a-z]{2}[\s]" << "#{next_year}" <<
|
28
|
-
"[\s][0-9]{2}[:][0-9]{2}[:][0-9]{2} GMT$")
|
29
|
-
res.headers.has_key?('Etag').should == false
|
30
|
-
res.headers.has_key?('Pragma').should == false
|
31
|
-
res.headers.has_key?('Last-Modified').should == false
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should return 404s if url root is known but it can't find the file" do
|
35
|
-
default_app_request
|
36
|
-
res = @request.get("/statics/foo")
|
37
|
-
res.should.be.not_found
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should call down the chain if url root is not known" do
|
41
|
-
default_app_request
|
42
|
-
res = @request.get("/something/else")
|
43
|
-
res.should.be.ok
|
44
|
-
res.body.should == "Hello World"
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should serve files if requested with version number and versioning is enabled" do
|
48
|
-
default_app_request
|
49
|
-
res = @request.get("/statics/test-0.0.1")
|
50
|
-
res.should.be.ok
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should change cache duration if specified thorugh option" do
|
54
|
-
configured_app_request
|
55
|
-
res = @request.get("/statics/test")
|
56
|
-
res.should.be.ok
|
57
|
-
res.body.should =~ /rubyrack/
|
58
|
-
next_next_year = Time.now().year + 2
|
59
|
-
res.headers['Expires'].should =~ Regexp.new("#{next_next_year}")
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should round max-age if duration is part of a year" do
|
63
|
-
one_week_duration_app_request
|
64
|
-
res = @request.get("/statics/test")
|
65
|
-
res.should.be.ok
|
66
|
-
res.body.should =~ /rubyrack/
|
67
|
-
res.headers['Cache-Control'].should == "max-age=606461, public"
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should return 404s if requested with version number but versioning is disabled" do
|
71
|
-
configured_app_request
|
72
|
-
res = @request.get("/statics/test-0.0.1")
|
73
|
-
res.should.be.not_found
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should serve files with plain headers when * is added to the directory name" do
|
77
|
-
configured_app_request
|
78
|
-
res = @request.get("/documents/test")
|
79
|
-
res.should.be.ok
|
80
|
-
res.body.should =~ /nocache/
|
81
|
-
next_next_year = Time.now().year + 2
|
82
|
-
res.headers['Expires'].should.not =~ Regexp.new("#{next_next_year}")
|
83
|
-
end
|
84
|
-
|
85
|
-
def default_app_request
|
86
|
-
@options = {:urls => ["/statics"], :root => @root}
|
87
|
-
request
|
88
|
-
end
|
89
|
-
|
90
|
-
def one_week_duration_app_request
|
91
|
-
@options = {:urls => ["/statics"], :root => @root, :duration => 1.fdiv(52)}
|
92
|
-
request
|
93
|
-
end
|
94
|
-
|
95
|
-
def configured_app_request
|
96
|
-
@options = {:urls => ["/statics", "/documents*"], :root => @root, :versioning => false, :duration => 2}
|
97
|
-
request
|
98
|
-
end
|
99
|
-
|
100
|
-
def request
|
101
|
-
@request = Rack::MockRequest.new(Rack::StaticCache.new(DummyApp.new, @options))
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'test/spec'
|
2
|
-
|
3
|
-
require 'rack'
|
4
|
-
require 'rack/contrib/try_static'
|
5
|
-
require 'rack/mock'
|
6
|
-
|
7
|
-
def build_options(opts)
|
8
|
-
{
|
9
|
-
:urls => %w[/],
|
10
|
-
:root => ::File.expand_path(::File.dirname(__FILE__)),
|
11
|
-
}.merge(opts)
|
12
|
-
end
|
13
|
-
|
14
|
-
def request(options = {})
|
15
|
-
@request =
|
16
|
-
Rack::MockRequest.new(
|
17
|
-
Rack::TryStatic.new(
|
18
|
-
lambda { |_| [200, {}, ["Hello World"]]},
|
19
|
-
options))
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "Rack::TryStatic" do
|
23
|
-
context 'when file cannot be found' do
|
24
|
-
it 'should call call app' do
|
25
|
-
res = request(build_options(:try => ['html'])).get('/documents')
|
26
|
-
res.should.be.ok
|
27
|
-
res.body.should == "Hello World"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'when file can be found' do
|
32
|
-
it 'should serve first found' do
|
33
|
-
res = request(build_options(:try => ['.html', '/index.html', '/index.htm'])).get('/documents')
|
34
|
-
res.should.be.ok
|
35
|
-
res.body.strip.should == "index.html"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'when path_info maps directly to file' do
|
40
|
-
it 'should serve existing' do
|
41
|
-
res = request(build_options(:try => ['/index.html'])).get('/documents/existing.html')
|
42
|
-
res.should.be.ok
|
43
|
-
res.body.strip.should == "existing.html"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
context 'when sharing options' do
|
48
|
-
it 'should not mutate given options' do
|
49
|
-
org_options = build_options :try => ['/index.html']
|
50
|
-
given_options = org_options.dup
|
51
|
-
request(given_options).get('/documents').should.be.ok
|
52
|
-
request(given_options).get('/documents').should.be.ok
|
53
|
-
given_options.should == org_options
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
data/test/statics/test
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rubyrack
|