Skip to content

Commit

Permalink
Make JSONP a noop when the status is 1xx, 204 or 304.
Browse files Browse the repository at this point in the history
  • Loading branch information
judofyr authored and aslakhellesoy committed Jun 22, 2010
1 parent 3a65d6e commit 952cb23
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rack/contrib/jsonp.rb
Expand Up @@ -20,6 +20,10 @@ def initialize(app)
def call(env)
status, headers, response = @app.call(env)

if STATUS_WITH_NO_ENTITY_BODY.include?(status)
return status, headers, response
end

headers = HeaderHash.new(headers)
request = Rack::Request.new(env)

Expand Down
9 changes: 9 additions & 0 deletions test/spec_rack_jsonp.rb
Expand Up @@ -70,4 +70,13 @@
body.should.equal [test_body]
end

specify "should not change anything if the request doesn't have a body" do
app1 = lambda { |env| [100, {}, []] }
app2 = lambda { |env| [204, {}, []] }
app3 = lambda { |env| [304, {}, []] }
request = Rack::MockRequest.env_for("/", :params => "callback=foo", 'HTTP_ACCEPT' => 'application/json')
Rack::JSONP.new(app1).call(request).should.equal app1.call({})
Rack::JSONP.new(app2).call(request).should.equal app2.call({})
Rack::JSONP.new(app3).call(request).should.equal app3.call({})
end
end

1 comment on commit 952cb23

@lawrencepit
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Please sign in to comment.