rack-jsonp 1.1.0 → 1.2.0

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.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2010 Cyril Rohr
1
+ Copyright (c) 2009-2011 Cyril Rohr
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -5,8 +5,8 @@ A Rack middleware for providing JSON-P support. Most of it is taken from the ori
5
5
  Since I don't want to include the complete rack-contrib gem when all I need is the JSONP middleware, I created this gem.
6
6
 
7
7
  == Contributions
8
- * Patches by Sebastián Gamboa (sagmor) and Garrett Bjerkhoel (dewski).
8
+ * Patches by Sebastián Gamboa (sagmor), Garrett Bjerkhoel (dewski) and Jason Morrison (jasonm).
9
9
 
10
10
  == Copyright
11
11
 
12
- Copyright (c) 2009-2010 Cyril Rohr. See LICENSE for details.
12
+ Copyright (c) 2009-2011 Cyril Rohr. See LICENSE for details.
data/Rakefile CHANGED
@@ -3,30 +3,12 @@ Bundler.setup
3
3
 
4
4
  require 'rake'
5
5
 
6
- begin
7
- require 'jeweler'
8
- Jeweler::Tasks.new do |gem|
9
- gem.name = "rack-jsonp"
10
- gem.summary = %Q{A Rack middleware for providing JSON-P support.}
11
- gem.description = %Q{A Rack middleware for providing JSON-P support.}
12
- gem.email = "cyril.rohr@gmail.com"
13
- gem.homepage = "http://github.com/crohr/rack-jsonp"
14
- gem.authors = ["Cyril Rohr"]
15
-
16
- gem.add_dependency('rack')
17
- gem.add_development_dependency('rake')
18
- gem.add_development_dependency('jeweler')
19
- gem.add_development_dependency('rspec', '< 2.0.0')
20
-
21
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
22
- end
23
-
24
- rescue LoadError
25
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
26
- end
6
+ lib = File.expand_path('../lib/', __FILE__)
7
+ $:.unshift lib unless $:.include?(lib)
8
+ require 'rack/jsonp'
27
9
 
28
10
  require 'spec/rake/spectask'
29
- Spec::Rake::SpecTask.new(:spec) do |spec|
11
+ Spec::Rake::SpecTask.new(:spec) do |spec|
30
12
  spec.libs << 'lib' << 'spec'
31
13
  spec.spec_files = FileList['spec/**/*_spec.rb']
32
14
  end
@@ -41,12 +23,7 @@ task :default => :spec
41
23
 
42
24
  require 'rake/rdoctask'
43
25
  Rake::RDocTask.new do |rdoc|
44
- if File.exist?('VERSION')
45
- version = File.read('VERSION')
46
- else
47
- version = ""
48
- end
49
-
26
+ version = Rack::JSONP::VERSION
50
27
  rdoc.rdoc_dir = 'rdoc'
51
28
  rdoc.title = "rack-jsonp #{version}"
52
29
  rdoc.rdoc_files.include('README*')
data/lib/rack/jsonp.rb CHANGED
@@ -1,28 +1,32 @@
1
+ require 'rack'
2
+
1
3
  module Rack
2
4
  # A Rack middleware for providing JSON-P support.
3
- #
5
+ #
4
6
  # Adapted from Flinn Mueller (http://actsasflinn.com/).
5
7
  #
6
8
  class JSONP
7
-
9
+
10
+ VERSION = "1.2.0"
11
+
8
12
  def initialize(app, options = {})
9
13
  @app = app
10
14
  @carriage_return = options[:carriage_return] || false
11
15
  @callback_param = options[:callback_param] || 'callback'
12
16
  end
13
-
17
+
14
18
  # Proxies the request to the application, stripping out the JSON-P callback
15
19
  # method and padding the response with the appropriate callback format.
16
- #
20
+ #
17
21
  # Changes nothing if no <tt>callback</tt> param is specified.
18
- #
22
+ #
19
23
  def call(env)
20
- # remove the callback and _ parameters BEFORE calling the backend,
24
+ # remove the callback and _ parameters BEFORE calling the backend,
21
25
  # so that caching middleware does not store a copy for each value of the callback parameter
22
26
  request = Rack::Request.new(env)
23
27
  callback = request.params.delete(@callback_param)
24
- env['QUERY_STRING'] = env['QUERY_STRING'].split("&").delete_if{|param| param =~ /^(_|#{@callback_param})/}.join("&")
25
-
28
+ env['QUERY_STRING'] = env['QUERY_STRING'].split("&").delete_if{|param| param =~ /^(_|#{@callback_param})=/}.join("&")
29
+
26
30
  status, headers, response = @app.call(env)
27
31
  if callback && headers['Content-Type'] =~ /json/i
28
32
  response = pad(callback, response)
@@ -35,23 +39,23 @@ module Rack
35
39
  end
36
40
  [status, headers, response]
37
41
  end
38
-
42
+
39
43
  # Pads the response with the appropriate callback format according to the
40
44
  # JSON-P spec/requirements.
41
- #
45
+ #
42
46
  # The Rack response spec indicates that it should be enumerable. The method
43
47
  # of combining all of the data into a single string makes sense since JSON
44
48
  # is returned as a full string.
45
- #
49
+ #
46
50
  def pad(callback, response, body = "")
47
51
  response.each{ |s| body << s.to_s }
48
52
  ["#{callback}(#{body})"]
49
53
  end
50
-
54
+
51
55
  def carriage_return(response, body = "")
52
56
  response.each{ |s| body << s.to_s }
53
57
  ["#{body}\n"]
54
58
  end
55
59
  end
56
-
57
- end
60
+
61
+ end
@@ -21,6 +21,30 @@ describe Rack::JSONP do
21
21
  body = Rack::JSONP.new(app, :callback_param => 'whatever').call(request).last
22
22
  body.should == ["#{callback}(#{test_body})"]
23
23
  end
24
+
25
+ it "removes the underscore parameter" do
26
+ test_body = '{"bar":"foo"}'
27
+ app_querystring = nil
28
+ app = lambda do |env|
29
+ app_querystring = env['QUERY_STRING']
30
+ [200, {'Content-Type' => 'application/json'}, [test_body]]
31
+ end
32
+ request = Rack::MockRequest.env_for("/", :params => "a=b&_=timestamp")
33
+ Rack::JSONP.new(app).call(request)
34
+ app_querystring.should == "a=b"
35
+ end
36
+
37
+ it "does not remove parameters that start with an underscore" do
38
+ test_body = '{"bar":"foo"}'
39
+ app_querystring = nil
40
+ app = lambda do |env|
41
+ app_querystring = env['QUERY_STRING']
42
+ [200, {'Content-Type' => 'application/json'}, [test_body]]
43
+ end
44
+ request = Rack::MockRequest.env_for("/", :params => "a=b&_=timestamp&_c=saveme")
45
+ Rack::JSONP.new(app).call(request)
46
+ app_querystring.should == "a=b&_c=saveme"
47
+ end
24
48
 
25
49
  it "should modify the content length to the correct value" do
26
50
  test_body = '{"bar":"foo"}'
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-jsonp
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 31
5
+ prerelease:
5
6
  segments:
6
7
  - 1
7
- - 1
8
+ - 2
8
9
  - 0
9
- version: 1.1.0
10
+ version: 1.2.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Cyril Rohr
@@ -14,65 +15,56 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-09-07 00:00:00 +02:00
18
+ date: 2011-06-06 00:00:00 +02:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: rack
23
+ prerelease: false
22
24
  requirement: &id001 !ruby/object:Gem::Requirement
23
25
  none: false
24
26
  requirements:
25
27
  - - ">="
26
28
  - !ruby/object:Gem::Version
29
+ hash: 3
27
30
  segments:
28
31
  - 0
29
32
  version: "0"
30
33
  type: :runtime
31
- prerelease: false
32
34
  version_requirements: *id001
33
35
  - !ruby/object:Gem::Dependency
34
36
  name: rake
37
+ prerelease: false
35
38
  requirement: &id002 !ruby/object:Gem::Requirement
36
39
  none: false
37
40
  requirements:
38
- - - ">="
41
+ - - ~>
39
42
  - !ruby/object:Gem::Version
43
+ hash: 27
40
44
  segments:
41
45
  - 0
42
- version: "0"
46
+ - 8
47
+ version: "0.8"
43
48
  type: :development
44
- prerelease: false
45
49
  version_requirements: *id002
46
50
  - !ruby/object:Gem::Dependency
47
- name: jeweler
51
+ name: rspec
52
+ prerelease: false
48
53
  requirement: &id003 !ruby/object:Gem::Requirement
49
54
  none: false
50
55
  requirements:
51
- - - ">="
56
+ - - ~>
52
57
  - !ruby/object:Gem::Version
58
+ hash: 9
53
59
  segments:
54
- - 0
55
- version: "0"
60
+ - 1
61
+ - 3
62
+ version: "1.3"
56
63
  type: :development
57
- prerelease: false
58
64
  version_requirements: *id003
59
- - !ruby/object:Gem::Dependency
60
- name: rspec
61
- requirement: &id004 !ruby/object:Gem::Requirement
62
- none: false
63
- requirements:
64
- - - <
65
- - !ruby/object:Gem::Version
66
- segments:
67
- - 2
68
- - 0
69
- - 0
70
- version: 2.0.0
71
- type: :development
72
- prerelease: false
73
- version_requirements: *id004
74
65
  description: A Rack middleware for providing JSON-P support.
75
- email: cyril.rohr@gmail.com
66
+ email:
67
+ - cyril.rohr@gmail.com
76
68
  executables: []
77
69
 
78
70
  extensions: []
@@ -81,17 +73,12 @@ extra_rdoc_files:
81
73
  - LICENSE
82
74
  - README.rdoc
83
75
  files:
84
- - .document
85
- - .gitignore
86
- - Gemfile
87
- - LICENSE
88
- - README.rdoc
89
- - Rakefile
90
- - VERSION
91
76
  - lib/rack/jsonp.rb
92
- - rack-jsonp.gemspec
93
77
  - spec/rack_jsonp_spec.rb
94
78
  - spec/spec_helper.rb
79
+ - Rakefile
80
+ - LICENSE
81
+ - README.rdoc
95
82
  has_rdoc: true
96
83
  homepage: http://github.com/crohr/rack-jsonp
97
84
  licenses: []
@@ -106,25 +93,28 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
93
  requirements:
107
94
  - - ">="
108
95
  - !ruby/object:Gem::Version
109
- hash: -3568420703856981526
96
+ hash: 31
110
97
  segments:
111
- - 0
112
- version: "0"
98
+ - 1
99
+ - 8
100
+ version: "1.8"
113
101
  required_rubygems_version: !ruby/object:Gem::Requirement
114
102
  none: false
115
103
  requirements:
116
104
  - - ">="
117
105
  - !ruby/object:Gem::Version
106
+ hash: 9
118
107
  segments:
119
- - 0
120
- version: "0"
108
+ - 1
109
+ - 3
110
+ version: "1.3"
121
111
  requirements: []
122
112
 
123
113
  rubyforge_project:
124
- rubygems_version: 1.3.7
114
+ rubygems_version: 1.5.2
125
115
  signing_key:
126
116
  specification_version: 3
127
117
  summary: A Rack middleware for providing JSON-P support.
128
118
  test_files:
129
- - spec/rack_jsonp_spec.rb
130
119
  - spec/spec_helper.rb
120
+ - spec/rack_jsonp_spec.rb
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
data/.gitignore DELETED
@@ -1,8 +0,0 @@
1
- *.sw?
2
- .DS_Store
3
- coverage
4
- rdoc
5
- pkg
6
- .bundle/
7
- Gemfile.lock
8
-
data/Gemfile DELETED
@@ -1,2 +0,0 @@
1
- source :rubygems
2
- gemspec
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.1.0
data/rack-jsonp.gemspec DELETED
@@ -1,64 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{rack-jsonp}
8
- s.version = "1.1.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Cyril Rohr"]
12
- s.date = %q{2010-09-07}
13
- s.description = %q{A Rack middleware for providing JSON-P support.}
14
- s.email = %q{cyril.rohr@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "Gemfile",
23
- "LICENSE",
24
- "README.rdoc",
25
- "Rakefile",
26
- "VERSION",
27
- "lib/rack/jsonp.rb",
28
- "rack-jsonp.gemspec",
29
- "spec/rack_jsonp_spec.rb",
30
- "spec/spec_helper.rb"
31
- ]
32
- s.homepage = %q{http://github.com/crohr/rack-jsonp}
33
- s.rdoc_options = ["--charset=UTF-8"]
34
- s.require_paths = ["lib"]
35
- s.rubygems_version = %q{1.3.7}
36
- s.summary = %q{A Rack middleware for providing JSON-P support.}
37
- s.test_files = [
38
- "spec/rack_jsonp_spec.rb",
39
- "spec/spec_helper.rb"
40
- ]
41
-
42
- if s.respond_to? :specification_version then
43
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
- s.specification_version = 3
45
-
46
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
- s.add_runtime_dependency(%q<rack>, [">= 0"])
48
- s.add_development_dependency(%q<rake>, [">= 0"])
49
- s.add_development_dependency(%q<jeweler>, [">= 0"])
50
- s.add_development_dependency(%q<rspec>, ["< 2.0.0"])
51
- else
52
- s.add_dependency(%q<rack>, [">= 0"])
53
- s.add_dependency(%q<rake>, [">= 0"])
54
- s.add_dependency(%q<jeweler>, [">= 0"])
55
- s.add_dependency(%q<rspec>, ["< 2.0.0"])
56
- end
57
- else
58
- s.add_dependency(%q<rack>, [">= 0"])
59
- s.add_dependency(%q<rake>, [">= 0"])
60
- s.add_dependency(%q<jeweler>, [">= 0"])
61
- s.add_dependency(%q<rspec>, ["< 2.0.0"])
62
- end
63
- end
64
-