rack-contrib-with-working-jsonp 0.9.2.1

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.
Files changed (56) hide show
  1. data/COPYING +18 -0
  2. data/README.rdoc +78 -0
  3. data/Rakefile +97 -0
  4. data/lib/rack/contrib.rb +37 -0
  5. data/lib/rack/contrib/accept_format.rb +46 -0
  6. data/lib/rack/contrib/backstage.rb +20 -0
  7. data/lib/rack/contrib/bounce_favicon.rb +16 -0
  8. data/lib/rack/contrib/callbacks.rb +37 -0
  9. data/lib/rack/contrib/config.rb +16 -0
  10. data/lib/rack/contrib/cookies.rb +50 -0
  11. data/lib/rack/contrib/csshttprequest.rb +39 -0
  12. data/lib/rack/contrib/deflect.rb +137 -0
  13. data/lib/rack/contrib/etag.rb +20 -0
  14. data/lib/rack/contrib/evil.rb +12 -0
  15. data/lib/rack/contrib/garbagecollector.rb +14 -0
  16. data/lib/rack/contrib/jsonp.rb +41 -0
  17. data/lib/rack/contrib/lighttpd_script_name_fix.rb +16 -0
  18. data/lib/rack/contrib/locale.rb +31 -0
  19. data/lib/rack/contrib/mailexceptions.rb +120 -0
  20. data/lib/rack/contrib/nested_params.rb +143 -0
  21. data/lib/rack/contrib/not_found.rb +18 -0
  22. data/lib/rack/contrib/post_body_content_type_parser.rb +40 -0
  23. data/lib/rack/contrib/proctitle.rb +30 -0
  24. data/lib/rack/contrib/profiler.rb +108 -0
  25. data/lib/rack/contrib/relative_redirect.rb +44 -0
  26. data/lib/rack/contrib/response_cache.rb +59 -0
  27. data/lib/rack/contrib/route_exceptions.rb +49 -0
  28. data/lib/rack/contrib/sendfile.rb +142 -0
  29. data/lib/rack/contrib/signals.rb +63 -0
  30. data/lib/rack/contrib/time_zone.rb +25 -0
  31. data/rack-contrib.gemspec +88 -0
  32. data/test/404.html +1 -0
  33. data/test/Maintenance.html +1 -0
  34. data/test/mail_settings.rb +12 -0
  35. data/test/spec_rack_accept_format.rb +72 -0
  36. data/test/spec_rack_backstage.rb +26 -0
  37. data/test/spec_rack_callbacks.rb +65 -0
  38. data/test/spec_rack_config.rb +22 -0
  39. data/test/spec_rack_contrib.rb +8 -0
  40. data/test/spec_rack_csshttprequest.rb +66 -0
  41. data/test/spec_rack_deflect.rb +107 -0
  42. data/test/spec_rack_etag.rb +23 -0
  43. data/test/spec_rack_evil.rb +19 -0
  44. data/test/spec_rack_garbagecollector.rb +13 -0
  45. data/test/spec_rack_jsonp.rb +34 -0
  46. data/test/spec_rack_lighttpd_script_name_fix.rb +16 -0
  47. data/test/spec_rack_mailexceptions.rb +97 -0
  48. data/test/spec_rack_nested_params.rb +46 -0
  49. data/test/spec_rack_not_found.rb +17 -0
  50. data/test/spec_rack_post_body_content_type_parser.rb +32 -0
  51. data/test/spec_rack_proctitle.rb +26 -0
  52. data/test/spec_rack_profiler.rb +37 -0
  53. data/test/spec_rack_relative_redirect.rb +78 -0
  54. data/test/spec_rack_response_cache.rb +137 -0
  55. data/test/spec_rack_sendfile.rb +86 -0
  56. metadata +174 -0
@@ -0,0 +1,78 @@
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
@@ -0,0 +1,137 @@
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
@@ -0,0 +1,86 @@
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
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-contrib-with-working-jsonp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.2.1
5
+ platform: ruby
6
+ authors:
7
+ - rack-devel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-07 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rack
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.1
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: test-spec
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: tmail
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "1.2"
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: json
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "1.1"
54
+ version:
55
+ description: Contributed Rack Middleware and Utilities with working JSON-P (edge rack-contrib as of Oct. 26)
56
+ email: rack-devel@googlegroups.com
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ extra_rdoc_files:
62
+ - README.rdoc
63
+ - COPYING
64
+ files:
65
+ - COPYING
66
+ - README.rdoc
67
+ - Rakefile
68
+ - lib/rack/contrib.rb
69
+ - lib/rack/contrib/accept_format.rb
70
+ - lib/rack/contrib/backstage.rb
71
+ - lib/rack/contrib/bounce_favicon.rb
72
+ - lib/rack/contrib/callbacks.rb
73
+ - lib/rack/contrib/config.rb
74
+ - lib/rack/contrib/cookies.rb
75
+ - lib/rack/contrib/csshttprequest.rb
76
+ - lib/rack/contrib/deflect.rb
77
+ - lib/rack/contrib/etag.rb
78
+ - lib/rack/contrib/evil.rb
79
+ - lib/rack/contrib/garbagecollector.rb
80
+ - lib/rack/contrib/jsonp.rb
81
+ - lib/rack/contrib/lighttpd_script_name_fix.rb
82
+ - lib/rack/contrib/locale.rb
83
+ - lib/rack/contrib/mailexceptions.rb
84
+ - lib/rack/contrib/nested_params.rb
85
+ - lib/rack/contrib/not_found.rb
86
+ - lib/rack/contrib/post_body_content_type_parser.rb
87
+ - lib/rack/contrib/proctitle.rb
88
+ - lib/rack/contrib/profiler.rb
89
+ - lib/rack/contrib/relative_redirect.rb
90
+ - lib/rack/contrib/response_cache.rb
91
+ - lib/rack/contrib/route_exceptions.rb
92
+ - lib/rack/contrib/sendfile.rb
93
+ - lib/rack/contrib/signals.rb
94
+ - lib/rack/contrib/time_zone.rb
95
+ - rack-contrib.gemspec
96
+ - test/404.html
97
+ - test/Maintenance.html
98
+ - test/mail_settings.rb
99
+ - test/spec_rack_accept_format.rb
100
+ - test/spec_rack_backstage.rb
101
+ - test/spec_rack_callbacks.rb
102
+ - test/spec_rack_config.rb
103
+ - test/spec_rack_contrib.rb
104
+ - test/spec_rack_csshttprequest.rb
105
+ - test/spec_rack_deflect.rb
106
+ - test/spec_rack_etag.rb
107
+ - test/spec_rack_evil.rb
108
+ - test/spec_rack_garbagecollector.rb
109
+ - test/spec_rack_jsonp.rb
110
+ - test/spec_rack_lighttpd_script_name_fix.rb
111
+ - test/spec_rack_mailexceptions.rb
112
+ - test/spec_rack_nested_params.rb
113
+ - test/spec_rack_not_found.rb
114
+ - test/spec_rack_post_body_content_type_parser.rb
115
+ - test/spec_rack_proctitle.rb
116
+ - test/spec_rack_profiler.rb
117
+ - test/spec_rack_relative_redirect.rb
118
+ - test/spec_rack_response_cache.rb
119
+ - test/spec_rack_sendfile.rb
120
+ has_rdoc: true
121
+ homepage: http://github.com/rack/rack-contrib/
122
+ licenses: []
123
+
124
+ post_install_message:
125
+ rdoc_options:
126
+ - --line-numbers
127
+ - --inline-source
128
+ - --title
129
+ - rack-contrib
130
+ - --main
131
+ - README
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: "0"
139
+ version:
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: "0"
145
+ version:
146
+ requirements: []
147
+
148
+ rubyforge_project:
149
+ rubygems_version: 1.3.5
150
+ signing_key:
151
+ specification_version: 2
152
+ summary: Didn't have time to wait for a new release.
153
+ test_files:
154
+ - test/spec_rack_accept_format.rb
155
+ - test/spec_rack_backstage.rb
156
+ - test/spec_rack_callbacks.rb
157
+ - test/spec_rack_config.rb
158
+ - test/spec_rack_contrib.rb
159
+ - test/spec_rack_csshttprequest.rb
160
+ - test/spec_rack_deflect.rb
161
+ - test/spec_rack_etag.rb
162
+ - test/spec_rack_evil.rb
163
+ - test/spec_rack_garbagecollector.rb
164
+ - test/spec_rack_jsonp.rb
165
+ - test/spec_rack_lighttpd_script_name_fix.rb
166
+ - test/spec_rack_mailexceptions.rb
167
+ - test/spec_rack_nested_params.rb
168
+ - test/spec_rack_not_found.rb
169
+ - test/spec_rack_post_body_content_type_parser.rb
170
+ - test/spec_rack_proctitle.rb
171
+ - test/spec_rack_profiler.rb
172
+ - test/spec_rack_relative_redirect.rb
173
+ - test/spec_rack_response_cache.rb
174
+ - test/spec_rack_sendfile.rb