Permalink
Browse files

Merge my JSONP to latest rack/master

  • Loading branch information...
runeb committed Jun 8, 2010
2 parents f95cffc + c0742aa commit 3e26836ea0b20f506c0aa37e1b59514b697f9c72
Showing with 133 additions and 81 deletions.
  1. +26 −0 AUTHORS
  2. +2 −2 README.rdoc
  3. +19 −20 Rakefile
  4. +1 −1 lib/rack/contrib/access.rb
  5. +1 −1 lib/rack/contrib/deflect.rb
  6. +11 −9 lib/rack/contrib/jsonp.rb
  7. +19 −5 rack-contrib.gemspec
  8. +28 −28 test/spec_rack_access.rb
  9. +10 −10 test/spec_rack_deflect.rb
  10. +16 −5 test/spec_rack_jsonp.rb
View
26 AUTHORS
@@ -0,0 +1,26 @@
+Ryan Tomayko <rtomayko@gmail.com>
+Joshua Peek <josh@joshpeek.com>
+Jeremy Kemper <jeremy@bitsweat.net>
+mynyml <mynyml@gmail.com>
+Cameron Walters <cameron.walters@gmail.com>
+Jon Crosby <jon@joncrosby.me>
+Matt Todd <chiology@gmail.com>
+Pirmin Kalberer <pka@sourcepole.ch>
+Rune Botten <rbotten@gmail.com>
+Pratik Naik <pratiknaik@gmail.com>
+Paul Sadauskas <psadauskas@gmail.com>
+Jeremy Evans <code@jeremyevans.net>
+Michael Fellinger <m.fellinger@gmail.com>
+Geoff Buesing <gbuesing@gmail.com>
+Nicolas Mérouze <nicolas.merouze@gmail.com>
+Cyril Rohr <cyril.rohr@irisa.fr>
+Harry Vangberg <harry@vangberg.name>
+James Rosen <jrosen@mitre.org>
+Mislav Marohnić <mislav.marohnic@gmail.com>
+Ben Brinckerhoff <ben@devver.net>
+Rafael Souza <rafael.ssouza@gmail.com>
+Stephen Delano <sdelano@sdelano-air.(none)>
+TJ Holowaychuk <tj@vision-media.ca>
+anupom syam <anupom.syam@gmail.com>
+ichverstehe <ichverstehe@gmail.com>
+kubicek <jiri@kubicek.cz>
View
@@ -54,9 +54,9 @@ Git is the quickest way to the rack-contrib sources:
git clone git://github.com/rack/rack-contrib.git
-Gems are currently available from GitHub clones:
+Gems are available too:
- gem install rack-rack-contrib --source=http://gems.github.com/
+ gem install rack-contrib
Requiring 'rack/contrib' will add autoloads to the Rack modules for all of the
components included. The following example shows what a simple rackup
View
@@ -42,32 +42,31 @@ task :rdoc => ["RDOX"]
# PACKAGING =================================================================
-if defined?(Gem)
- # load gemspec
- $spec = eval(File.read('rack-contrib.gemspec'))
+require 'rubygems'
+# load gemspec
+$spec = eval(File.read('rack-contrib.gemspec'))
- def package(ext='')
- "pkg/rack-contrib-#{$spec.version}" + ext
- end
+def package(ext='')
+ "pkg/rack-contrib-#{$spec.version}" + ext
+end
- desc 'Build packages'
- task :package => %w[.gem .tar.gz].map {|e| package(e)}
+desc 'Build packages'
+task :package => %w[.gem .tar.gz].map {|e| package(e)}
- desc 'Build and install as local gem'
- task :install => package('.gem') do
- sh "gem install #{package('.gem')}"
- end
+desc 'Build and install as local gem'
+task :install => package('.gem') do
+ sh "gem install #{package('.gem')}"
+end
- directory 'pkg/'
+directory 'pkg/'
- file package('.gem') => %w[pkg/ rack-contrib.gemspec] + $spec.files do |f|
- sh "gem build rack-contrib.gemspec"
- mv File.basename(f.name), f.name
- end
+file package('.gem') => %w[pkg/ rack-contrib.gemspec] + $spec.files do |f|
+ sh "gem build rack-contrib.gemspec"
+ mv File.basename(f.name), f.name
+end
- file package('.tar.gz') => %w[pkg/] + $spec.files do |f|
- sh "git archive --format=tar HEAD | gzip > #{f.name}"
- end
+file package('.tar.gz') => %w[pkg/] + $spec.files do |f|
+ sh "git archive --format=tar HEAD | gzip > #{f.name}"
end
# GEMSPEC ===================================================================
@@ -70,7 +70,7 @@ def ipmasks_for_path(env)
end
def forbidden!
- [403, { 'Content-Type' => 'text/html', 'Content-Length' => '0' }, '']
+ [403, { 'Content-Type' => 'text/html', 'Content-Length' => '0' }, []]
end
def ip_authorized?(ipmasks)
@@ -63,7 +63,7 @@ def call env
end
def deflect!
- [403, { 'Content-Type' => 'text/html', 'Content-Length' => '0' }, '']
+ [403, { 'Content-Type' => 'text/html', 'Content-Length' => '0' }, []]
end
def deflect? env
View
@@ -6,6 +6,7 @@ module Rack
#
class JSONP
include Rack::Utils
+
def initialize(app)
@app = app
end
@@ -18,10 +19,11 @@ def initialize(app)
#
def call(env)
status, headers, response = @app.call(env)
+
headers = HeaderHash.new(headers)
request = Rack::Request.new(env)
- if is_json?(headers['Content-Type']) && has_callback?(request.params)
+ if is_json?(headers) && has_callback?(request)
response = pad(request.params.delete('callback'), response)
# No longer json, its javascript!
@@ -40,24 +42,24 @@ def call(env)
private
- def is_json?(header)
- header.include?('application/json')
+ def is_json?(headers)
+ headers['Content-Type'].include?('application/json')
end
- def has_callback?(params)
- params.include?('callback')
+ def has_callback?(request)
+ request.params.include?('callback')
end
# Pads the response with the appropriate callback format according to the
# JSON-P spec/requirements.
#
- # The Rack response spec indicates that it should be enumerable. The method
- # of combining all of the data into a single string makes sense since JSON
- # is returned as a full string.
+ # The Rack response spec indicates that it should be enumerable. The
+ # method of combining all of the data into a single string makes sense
+ # since JSON is returned as a full string.
#
def pad(callback, response, body = "")
response.each{ |s| body << s.to_s }
- "#{callback}(#{body})"
+ ["#{callback}(#{body})"]
end
end
View
@@ -3,8 +3,8 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.name = 'rack-contrib'
- s.version = '0.9.3'
- s.date = '2010-01-10'
+ s.version = '1.0.0'
+ s.date = '2010-06-07'
s.description = "Contributed Rack Middleware and Utilities"
s.summary = "Contributed Rack Middleware and Utilities"
@@ -14,6 +14,7 @@ Gem::Specification.new do |s|
# = MANIFEST =
s.files = %w[
+ AUTHORS
COPYING
README.rdoc
Rakefile
@@ -27,9 +28,10 @@ Gem::Specification.new do |s|
lib/rack/contrib/cookies.rb
lib/rack/contrib/csshttprequest.rb
lib/rack/contrib/deflect.rb
- lib/rack/contrib/etag.rb
lib/rack/contrib/evil.rb
+ lib/rack/contrib/expectation_cascade.rb
lib/rack/contrib/garbagecollector.rb
+ lib/rack/contrib/host_meta.rb
lib/rack/contrib/jsonp.rb
lib/rack/contrib/lighttpd_script_name_fix.rb
lib/rack/contrib/locale.rb
@@ -41,25 +43,32 @@ Gem::Specification.new do |s|
lib/rack/contrib/profiler.rb
lib/rack/contrib/relative_redirect.rb
lib/rack/contrib/response_cache.rb
+ lib/rack/contrib/response_headers.rb
lib/rack/contrib/route_exceptions.rb
+ lib/rack/contrib/runtime.rb
lib/rack/contrib/sendfile.rb
lib/rack/contrib/signals.rb
+ lib/rack/contrib/simple_endpoint.rb
+ lib/rack/contrib/static_cache.rb
lib/rack/contrib/time_zone.rb
rack-contrib.gemspec
test/404.html
test/Maintenance.html
+ test/documents/test
test/mail_settings.rb
test/spec_rack_accept_format.rb
test/spec_rack_access.rb
test/spec_rack_backstage.rb
test/spec_rack_callbacks.rb
test/spec_rack_config.rb
test/spec_rack_contrib.rb
+ test/spec_rack_cookies.rb
test/spec_rack_csshttprequest.rb
test/spec_rack_deflect.rb
- test/spec_rack_etag.rb
test/spec_rack_evil.rb
+ test/spec_rack_expectation_cascade.rb
test/spec_rack_garbagecollector.rb
+ test/spec_rack_host_meta.rb
test/spec_rack_jsonp.rb
test/spec_rack_lighttpd_script_name_fix.rb
test/spec_rack_mailexceptions.rb
@@ -70,15 +79,20 @@ Gem::Specification.new do |s|
test/spec_rack_profiler.rb
test/spec_rack_relative_redirect.rb
test/spec_rack_response_cache.rb
+ test/spec_rack_response_headers.rb
+ test/spec_rack_runtime.rb
test/spec_rack_sendfile.rb
+ test/spec_rack_simple_endpoint.rb
+ test/spec_rack_static_cache.rb
+ test/statics/test
]
# = MANIFEST =
s.test_files = s.files.select {|path| path =~ /^test\/spec_.*\.rb/}
s.extra_rdoc_files = %w[README.rdoc COPYING]
s.add_dependency 'rack', '>= 0.9.1'
- s.add_development_dependency 'test-spec', '~> 0.9.0'
+ s.add_development_dependency 'test-spec', '>= 0.9.0'
s.add_development_dependency 'tmail', '>= 1.2'
s.add_development_dependency 'json', '>= 1.1'
Oops, something went wrong.

0 comments on commit 3e26836

Please sign in to comment.