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
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'test/spec'
|
2
|
-
require 'rack/mock'
|
3
|
-
require 'rack/contrib/nested_params'
|
4
|
-
require 'rack/methodoverride'
|
5
|
-
|
6
|
-
context Rack::NestedParams do
|
7
|
-
|
8
|
-
App = lambda { |env| [200, {'Content-Type' => 'text/plain'}, Rack::Request.new(env)] }
|
9
|
-
|
10
|
-
def env_for_post_with_headers(path, headers, body)
|
11
|
-
Rack::MockRequest.env_for(path, {:method => "POST", :input => body}.merge(headers))
|
12
|
-
end
|
13
|
-
|
14
|
-
def form_post(params, content_type = 'application/x-www-form-urlencoded')
|
15
|
-
params = Rack::Utils.build_query(params) if Hash === params
|
16
|
-
env_for_post_with_headers('/', {'CONTENT_TYPE' => content_type}, params)
|
17
|
-
end
|
18
|
-
|
19
|
-
def middleware
|
20
|
-
Rack::NestedParams.new(App)
|
21
|
-
end
|
22
|
-
|
23
|
-
specify "should handle requests with POST body Content-Type of application/x-www-form-urlencoded" do
|
24
|
-
req = middleware.call(form_post({'foo[bar][baz]' => 'nested'})).last
|
25
|
-
req.POST.should.equal({"foo" => { "bar" => { "baz" => "nested" }}})
|
26
|
-
end
|
27
|
-
|
28
|
-
specify "should not parse requests with other Content-Type" do
|
29
|
-
req = middleware.call(form_post({'foo[bar][baz]' => 'nested'}, 'text/plain')).last
|
30
|
-
req.POST.should.equal({})
|
31
|
-
end
|
32
|
-
|
33
|
-
specify "should work even after another middleware already parsed the request" do
|
34
|
-
app = Rack::MethodOverride.new(middleware)
|
35
|
-
req = app.call(form_post({'_method' => 'put', 'foo[bar]' => 'nested'})).last
|
36
|
-
req.POST.should.equal({'_method' => 'put', "foo" => { "bar" => "nested" }})
|
37
|
-
req.put?.should.equal true
|
38
|
-
end
|
39
|
-
|
40
|
-
specify "should make first boolean have precedence even after request already parsed" do
|
41
|
-
app = Rack::MethodOverride.new(middleware)
|
42
|
-
req = app.call(form_post("foo=1&foo=0")).last
|
43
|
-
req.POST.should.equal({"foo" => '1'})
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
data/test/spec_rack_not_found.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'test/spec'
|
2
|
-
require 'rack/mock'
|
3
|
-
require 'rack/contrib/not_found'
|
4
|
-
|
5
|
-
context "Rack::NotFound" do
|
6
|
-
|
7
|
-
specify "should render the file at the given path for all requests" do
|
8
|
-
app = Rack::Builder.new do
|
9
|
-
use Rack::Lint
|
10
|
-
run Rack::NotFound.new('test/404.html')
|
11
|
-
end
|
12
|
-
response = Rack::MockRequest.new(app).get('/')
|
13
|
-
response.body.should.equal('Not Found')
|
14
|
-
response.status.should.equal(404)
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'test/spec'
|
2
|
-
require 'rack/mock'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rack/contrib/post_body_content_type_parser'
|
6
|
-
|
7
|
-
context "Rack::PostBodyContentTypeParser" do
|
8
|
-
|
9
|
-
specify "should parse 'application/json' requests" do
|
10
|
-
params = params_for_request '{"key":"value"}', "application/json"
|
11
|
-
params['key'].should.equal "value"
|
12
|
-
end
|
13
|
-
|
14
|
-
specify "should parse 'application/json; charset=utf-8' requests" do
|
15
|
-
params = params_for_request '{"key":"value"}', "application/json; charset=utf-8"
|
16
|
-
params['key'].should.equal "value"
|
17
|
-
end
|
18
|
-
|
19
|
-
specify "should parse 'application/json' requests with empty body" do
|
20
|
-
params = params_for_request "", "application/json"
|
21
|
-
params.should.equal({})
|
22
|
-
end
|
23
|
-
|
24
|
-
specify "shouldn't affect form-urlencoded requests" do
|
25
|
-
params = params_for_request("key=value", "application/x-www-form-urlencoded")
|
26
|
-
params['key'].should.equal "value"
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
def params_for_request(body, content_type)
|
32
|
-
env = Rack::MockRequest.env_for "/", {:method => "POST", :input => body, "CONTENT_TYPE" => content_type}
|
33
|
-
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, Rack::Request.new(env).POST] }
|
34
|
-
Rack::PostBodyContentTypeParser.new(app).call(env).last
|
35
|
-
end
|
36
|
-
|
37
|
-
rescue LoadError => e
|
38
|
-
# Missing dependency JSON, skipping tests.
|
39
|
-
STDERR.puts "WARN: Skipping Rack::PostBodyContentTypeParser tests (json not installed)"
|
40
|
-
end
|
data/test/spec_rack_proctitle.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'test/spec'
|
2
|
-
require 'rack/mock'
|
3
|
-
require 'rack/contrib/proctitle'
|
4
|
-
|
5
|
-
context "Rack::ProcTitle" do
|
6
|
-
F = ::File
|
7
|
-
|
8
|
-
progname = File.basename($0)
|
9
|
-
appname = F.expand_path(__FILE__).split('/')[-3]
|
10
|
-
|
11
|
-
def simple_app(body=['Hello World!'])
|
12
|
-
lambda { |env| [200, {'Content-Type' => 'text/plain'}, body] }
|
13
|
-
end
|
14
|
-
|
15
|
-
specify "should set the process title when created" do
|
16
|
-
Rack::ProcTitle.new(simple_app)
|
17
|
-
$0.should.equal "#{progname} [#{appname}] init ..."
|
18
|
-
end
|
19
|
-
|
20
|
-
specify "should set the process title on each request" do
|
21
|
-
app = Rack::ProcTitle.new(simple_app)
|
22
|
-
req = Rack::MockRequest.new(app)
|
23
|
-
10.times { req.get('/hello') }
|
24
|
-
$0.should.equal "#{progname} [#{appname}/80] (10) GET /hello"
|
25
|
-
end
|
26
|
-
end
|
data/test/spec_rack_profiler.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'test/spec'
|
2
|
-
require 'rack/mock'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rack/contrib/profiler'
|
6
|
-
|
7
|
-
context 'Rack::Profiler' do
|
8
|
-
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, 'Oh hai der'] }
|
9
|
-
request = Rack::MockRequest.env_for("/", :params => "profile=process_time")
|
10
|
-
|
11
|
-
specify 'printer defaults to RubyProf::CallStackPrinter' do
|
12
|
-
profiler = Rack::Profiler.new(nil)
|
13
|
-
profiler.instance_variable_get('@printer').should.equal RubyProf::CallStackPrinter
|
14
|
-
profiler.instance_variable_get('@times').should.equal 1
|
15
|
-
end
|
16
|
-
|
17
|
-
specify 'CallStackPrinter has Content-Type test/html' do
|
18
|
-
headers = Rack::Profiler.new(app, :printer => :call_stack).call(request)[1]
|
19
|
-
headers.should.equal "Content-Type"=>"text/html"
|
20
|
-
end
|
21
|
-
|
22
|
-
specify 'CallTreePrinter has correct headers' do
|
23
|
-
headers = Rack::Profiler.new(app, :printer => :call_tree).call(request)[1]
|
24
|
-
headers.should.equal "Content-Disposition"=>"attachment; filename=\"/.process_time.tree\"", "Content-Type"=>"application/octet-stream"
|
25
|
-
end
|
26
|
-
|
27
|
-
specify 'FlatPrinter and GraphPrinter has Content-Type text/plain' do
|
28
|
-
%w(flat graph).each do |printer|
|
29
|
-
headers = Rack::Profiler.new(app, :printer => printer.to_sym).call(request)[1]
|
30
|
-
headers.should.equal "Content-Type"=>"text/plain"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
specify 'GraphHtmlPrinter has Content-Type text/html' do
|
35
|
-
headers = Rack::Profiler.new(app, :printer => :graph_html).call(request)[1]
|
36
|
-
headers.should.equal "Content-Type"=>"text/html"
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
rescue LoadError => boom
|
41
|
-
$stderr.puts "WARN: Skipping Rack::Profiler tests (ruby-prof not installed)"
|
42
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
require 'test/spec'
|
2
|
-
require 'rack/mock'
|
3
|
-
require 'rack/contrib/relative_redirect'
|
4
|
-
require 'fileutils'
|
5
|
-
|
6
|
-
context Rack::RelativeRedirect do
|
7
|
-
def request(opts={}, &block)
|
8
|
-
@def_status = opts[:status] if opts[:status]
|
9
|
-
@def_location = opts[:location] if opts[:location]
|
10
|
-
yield Rack::MockRequest.new(Rack::RelativeRedirect.new(@def_app, &opts[:block])).get(opts[:path]||@def_path, opts[:headers]||{})
|
11
|
-
end
|
12
|
-
|
13
|
-
setup do
|
14
|
-
@def_path = '/path/to/blah'
|
15
|
-
@def_status = 301
|
16
|
-
@def_location = '/redirect/to/blah'
|
17
|
-
@def_app = lambda { |env| [@def_status, {'Location' => @def_location}, [""]]}
|
18
|
-
end
|
19
|
-
|
20
|
-
specify "should make the location url an absolute url if currently a relative url" do
|
21
|
-
request do |r|
|
22
|
-
r.status.should.equal(301)
|
23
|
-
r.headers['Location'].should.equal('http://example.org/redirect/to/blah')
|
24
|
-
end
|
25
|
-
request(:status=>302, :location=>'/redirect') do |r|
|
26
|
-
r.status.should.equal(302)
|
27
|
-
r.headers['Location'].should.equal('http://example.org/redirect')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
specify "should use the request path if the relative url is given and doesn't start with a slash" do
|
32
|
-
request(:status=>303, :location=>'redirect/to/blah') do |r|
|
33
|
-
r.status.should.equal(303)
|
34
|
-
r.headers['Location'].should.equal('http://example.org/path/to/redirect/to/blah')
|
35
|
-
end
|
36
|
-
request(:status=>303, :location=>'redirect') do |r|
|
37
|
-
r.status.should.equal(303)
|
38
|
-
r.headers['Location'].should.equal('http://example.org/path/to/redirect')
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
specify "should use a given block to make the url absolute" do
|
43
|
-
request(:block=>proc{|env, res| "https://example.org"}) do |r|
|
44
|
-
r.status.should.equal(301)
|
45
|
-
r.headers['Location'].should.equal('https://example.org/redirect/to/blah')
|
46
|
-
end
|
47
|
-
request(:status=>303, :location=>'/redirect', :block=>proc{|env, res| "https://e.org:9999/blah"}) do |r|
|
48
|
-
r.status.should.equal(303)
|
49
|
-
r.headers['Location'].should.equal('https://e.org:9999/blah/redirect')
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
specify "should not modify the location url unless the response is a redirect" do
|
54
|
-
status = 200
|
55
|
-
@def_app = lambda { |env| [status, {'Content-Type' => "text/html"}, [""]]}
|
56
|
-
request do |r|
|
57
|
-
r.status.should.equal(200)
|
58
|
-
r.headers.should.not.include?('Location')
|
59
|
-
end
|
60
|
-
status = 404
|
61
|
-
@def_app = lambda { |env| [status, {'Content-Type' => "text/html", 'Location' => 'redirect'}, [""]]}
|
62
|
-
request do |r|
|
63
|
-
r.status.should.equal(404)
|
64
|
-
r.headers['Location'].should.equal('redirect')
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
specify "should not modify the location url if it is already an absolute url" do
|
69
|
-
request(:location=>'https://example.org/') do |r|
|
70
|
-
r.status.should.equal(301)
|
71
|
-
r.headers['Location'].should.equal('https://example.org/')
|
72
|
-
end
|
73
|
-
request(:status=>302, :location=>'https://e.org:9999/redirect') do |r|
|
74
|
-
r.status.should.equal(302)
|
75
|
-
r.headers['Location'].should.equal('https://e.org:9999/redirect')
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
@@ -1,137 +0,0 @@
|
|
1
|
-
require 'test/spec'
|
2
|
-
require 'rack/mock'
|
3
|
-
require 'rack/contrib/response_cache'
|
4
|
-
require 'fileutils'
|
5
|
-
|
6
|
-
context Rack::ResponseCache do
|
7
|
-
F = ::File
|
8
|
-
|
9
|
-
def request(opts={}, &block)
|
10
|
-
Rack::MockRequest.new(Rack::ResponseCache.new(block||@def_app, opts[:cache]||@cache, &opts[:rc_block])).send(opts[:meth]||:get, opts[:path]||@def_path, opts[:headers]||{})
|
11
|
-
end
|
12
|
-
|
13
|
-
setup do
|
14
|
-
@cache = {}
|
15
|
-
@def_disk_cache = F.join(F.dirname(__FILE__), 'response_cache_test_disk_cache')
|
16
|
-
@def_value = ["rack-response-cache"]
|
17
|
-
@def_path = '/path/to/blah'
|
18
|
-
@def_app = lambda { |env| [200, {'Content-Type' => env['CT'] || 'text/html'}, @def_value]}
|
19
|
-
end
|
20
|
-
teardown do
|
21
|
-
FileUtils.rm_rf(@def_disk_cache)
|
22
|
-
end
|
23
|
-
|
24
|
-
specify "should cache results to disk if cache is a string" do
|
25
|
-
request(:cache=>@def_disk_cache)
|
26
|
-
F.read(F.join(@def_disk_cache, 'path', 'to', 'blah.html')).should.equal @def_value.first
|
27
|
-
request(:path=>'/path/3', :cache=>@def_disk_cache)
|
28
|
-
F.read(F.join(@def_disk_cache, 'path', '3.html')).should.equal @def_value.first
|
29
|
-
end
|
30
|
-
|
31
|
-
specify "should cache results to given cache if cache is not a string" do
|
32
|
-
request
|
33
|
-
@cache.should.equal('/path/to/blah.html'=>@def_value)
|
34
|
-
request(:path=>'/path/3')
|
35
|
-
@cache.should.equal('/path/to/blah.html'=>@def_value, '/path/3.html'=>@def_value)
|
36
|
-
end
|
37
|
-
|
38
|
-
specify "should not CACHE RESults if request method is not GET" do
|
39
|
-
request(:meth=>:post)
|
40
|
-
@cache.should.equal({})
|
41
|
-
request(:meth=>:put)
|
42
|
-
@cache.should.equal({})
|
43
|
-
request(:meth=>:delete)
|
44
|
-
@cache.should.equal({})
|
45
|
-
end
|
46
|
-
|
47
|
-
specify "should not cache results if there is a query string" do
|
48
|
-
request(:path=>'/path/to/blah?id=1')
|
49
|
-
@cache.should.equal({})
|
50
|
-
request(:path=>'/path/to/?id=1')
|
51
|
-
@cache.should.equal({})
|
52
|
-
request(:path=>'/?id=1')
|
53
|
-
@cache.should.equal({})
|
54
|
-
end
|
55
|
-
|
56
|
-
specify "should cache results if there is an empty query string" do
|
57
|
-
request(:path=>'/?')
|
58
|
-
@cache.should.equal('/index.html'=>@def_value)
|
59
|
-
end
|
60
|
-
|
61
|
-
specify "should not cache results if the request is not sucessful (status 200)" do
|
62
|
-
request{|env| [404, {'Content-Type' => 'text/html'}, ['']]}
|
63
|
-
@cache.should.equal({})
|
64
|
-
request{|env| [500, {'Content-Type' => 'text/html'}, ['']]}
|
65
|
-
@cache.should.equal({})
|
66
|
-
request{|env| [302, {'Content-Type' => 'text/html'}, ['']]}
|
67
|
-
@cache.should.equal({})
|
68
|
-
end
|
69
|
-
|
70
|
-
specify "should not cache results if the block returns nil or false" do
|
71
|
-
request(:rc_block=>proc{false})
|
72
|
-
@cache.should.equal({})
|
73
|
-
request(:rc_block=>proc{nil})
|
74
|
-
@cache.should.equal({})
|
75
|
-
end
|
76
|
-
|
77
|
-
specify "should cache results to path returned by block" do
|
78
|
-
request(:rc_block=>proc{"1"})
|
79
|
-
@cache.should.equal("1"=>@def_value)
|
80
|
-
request(:rc_block=>proc{"2"})
|
81
|
-
@cache.should.equal("1"=>@def_value, "2"=>@def_value)
|
82
|
-
end
|
83
|
-
|
84
|
-
specify "should pass the environment and response to the block" do
|
85
|
-
e, r = nil, nil
|
86
|
-
request(:rc_block=>proc{|env,res| e, r = env, res; nil})
|
87
|
-
e['PATH_INFO'].should.equal @def_path
|
88
|
-
e['REQUEST_METHOD'].should.equal 'GET'
|
89
|
-
e['QUERY_STRING'].should.equal ''
|
90
|
-
r.should.equal([200, {"Content-Type"=>"text/html"}, ["rack-response-cache"]])
|
91
|
-
end
|
92
|
-
|
93
|
-
specify "should unescape the path by default" do
|
94
|
-
request(:path=>'/path%20with%20spaces')
|
95
|
-
@cache.should.equal('/path with spaces.html'=>@def_value)
|
96
|
-
request(:path=>'/path%3chref%3e')
|
97
|
-
@cache.should.equal('/path with spaces.html'=>@def_value, '/path<href>.html'=>@def_value)
|
98
|
-
end
|
99
|
-
|
100
|
-
specify "should cache html, css, and xml responses by default" do
|
101
|
-
request(:path=>'/a')
|
102
|
-
@cache.should.equal('/a.html'=>@def_value)
|
103
|
-
request(:path=>'/b', :headers=>{'CT'=>'text/xml'})
|
104
|
-
@cache.should.equal('/a.html'=>@def_value, '/b.xml'=>@def_value)
|
105
|
-
request(:path=>'/c', :headers=>{'CT'=>'text/css'})
|
106
|
-
@cache.should.equal('/a.html'=>@def_value, '/b.xml'=>@def_value, '/c.css'=>@def_value)
|
107
|
-
end
|
108
|
-
|
109
|
-
specify "should cache responses by default with the extension added if not already present" do
|
110
|
-
request(:path=>'/a.html')
|
111
|
-
@cache.should.equal('/a.html'=>@def_value)
|
112
|
-
request(:path=>'/b.xml', :headers=>{'CT'=>'text/xml'})
|
113
|
-
@cache.should.equal('/a.html'=>@def_value, '/b.xml'=>@def_value)
|
114
|
-
request(:path=>'/c.css', :headers=>{'CT'=>'text/css'})
|
115
|
-
@cache.should.equal('/a.html'=>@def_value, '/b.xml'=>@def_value, '/c.css'=>@def_value)
|
116
|
-
end
|
117
|
-
|
118
|
-
specify "should not delete existing extensions" do
|
119
|
-
request(:path=>'/d.css', :headers=>{'CT'=>'text/html'})
|
120
|
-
@cache.should.equal('/d.css.html'=>@def_value)
|
121
|
-
end
|
122
|
-
|
123
|
-
specify "should cache html responses with empty basename to index.html by default" do
|
124
|
-
request(:path=>'/')
|
125
|
-
@cache.should.equal('/index.html'=>@def_value)
|
126
|
-
request(:path=>'/blah/')
|
127
|
-
@cache.should.equal('/index.html'=>@def_value, '/blah/index.html'=>@def_value)
|
128
|
-
request(:path=>'/blah/2/')
|
129
|
-
@cache.should.equal('/index.html'=>@def_value, '/blah/index.html'=>@def_value, '/blah/2/index.html'=>@def_value)
|
130
|
-
end
|
131
|
-
|
132
|
-
specify "should raise an error if a cache argument is not provided" do
|
133
|
-
app = Rack::Builder.new{use Rack::ResponseCache; run lambda { |env| [200, {'Content-Type' => 'text/plain'}, Rack::Request.new(env).POST]}}
|
134
|
-
proc{Rack::MockRequest.new(app).get('/')}.should.raise(ArgumentError)
|
135
|
-
end
|
136
|
-
|
137
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'test/spec'
|
2
|
-
require 'rack'
|
3
|
-
require 'rack/contrib/response_headers'
|
4
|
-
|
5
|
-
context "Rack::ResponseHeaders" do
|
6
|
-
|
7
|
-
specify "yields a HeaderHash of response headers" do
|
8
|
-
orig_headers = {'X-Foo' => 'foo', 'X-Bar' => 'bar'}
|
9
|
-
app = Proc.new {[200, orig_headers, []]}
|
10
|
-
middleware = Rack::ResponseHeaders.new(app) do |headers|
|
11
|
-
assert_instance_of Rack::Utils::HeaderHash, headers
|
12
|
-
orig_headers.should == headers
|
13
|
-
end
|
14
|
-
middleware.call({})
|
15
|
-
end
|
16
|
-
|
17
|
-
specify "allows adding headers" do
|
18
|
-
app = Proc.new {[200, {'X-Foo' => 'foo'}, []]}
|
19
|
-
middleware = Rack::ResponseHeaders.new(app) do |headers|
|
20
|
-
headers['X-Bar'] = 'bar'
|
21
|
-
end
|
22
|
-
r = middleware.call({})
|
23
|
-
r[1].should == {'X-Foo' => 'foo', 'X-Bar' => 'bar'}
|
24
|
-
end
|
25
|
-
|
26
|
-
specify "allows deleting headers" do
|
27
|
-
app = Proc.new {[200, {'X-Foo' => 'foo', 'X-Bar' => 'bar'}, []]}
|
28
|
-
middleware = Rack::ResponseHeaders.new(app) do |headers|
|
29
|
-
headers.delete('X-Bar')
|
30
|
-
end
|
31
|
-
r = middleware.call({})
|
32
|
-
r[1].should == {'X-Foo' => 'foo'}
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
data/test/spec_rack_runtime.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'test/spec'
|
2
|
-
require 'rack/mock'
|
3
|
-
require 'rack/contrib/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
|