Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
PATH
remote: .
specs:
rack-jsonp-middleware (0.0.5)
rack-jsonp-middleware (0.0.7)
rack

GEM
remote: http://rubygems.org/
specs:
diff-lcs (1.1.2)
rack (1.2.1)
rack (1.4.1)
rake (10.0.0)
rspec (2.5.0)
rspec-core (~> 2.5.0)
rspec-expectations (~> 2.5.0)
Expand All @@ -23,4 +24,5 @@ PLATFORMS

DEPENDENCIES
rack-jsonp-middleware!
rake
rspec (>= 1.3.0)
2 changes: 1 addition & 1 deletion lib/rack/jsonp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(app)

def call(env)
request = Rack::Request.new(env)
requesting_jsonp = Pathname(request.env['PATH_INFO']).extname =~ /^\.jsonp$/i
requesting_jsonp = ( Pathname(request.env['PATH_INFO']).extname =~ /^\.jsonp$/i || request.params['format'] == 'jsonp')
callback = request.params['callback']

return [400,{},[]] if requesting_jsonp && !self.valid_callback?(callback)
Expand Down
24 changes: 24 additions & 0 deletions spec/jsonp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,30 @@
end

end

describe 'using format attribute instead of path extension' do
before :each do
@request = Rack::MockRequest.env_for("/action?callback=#{@callback}&format=jsonp")
@jsonp_response = Rack::JSONP.new(@app).call(@request)
@jsonp_response_status, @jsonp_response_headers, @jsonp_response_body = @jsonp_response
end

it 'should not modify the response status code' do
@jsonp_response_status.should == @response_status
end

it 'should update the response content length to the new value' do
@jsonp_response_headers['Content-Length'].should == '32'
end

it 'should set the response content type as application/javascript' do
@jsonp_response_headers['Content-Type'].should == 'application/javascript'
end

it 'should wrap the response body in the Javasript callback' do
@jsonp_response_body.should == ["#{@callback}(#{@response_body.first});"]
end
end

describe 'when a valid jsonp request is made with multibyte characters' do

Expand Down