Permalink
Browse files

Modify JSONP middleware to not fail if Content-Type header is missing

  • Loading branch information...
1 parent 47661fa commit ea13fab9a1151cde21c147fac0f0f206ba75efd2 @matth matth committed with manveru Sep 2, 2010
Showing with 9 additions and 1 deletion.
  1. +1 −1 lib/rack/contrib/jsonp.rb
  2. +8 −0 test/spec_rack_jsonp.rb
@@ -41,7 +41,7 @@ def call(env)
private
def is_json?(headers)
- headers['Content-Type'].include?('application/json')
+ headers.key?('Content-Type') && headers['Content-Type'].include?('application/json')
end
def has_callback?(request)
View
@@ -69,5 +69,13 @@
body = Rack::JSONP.new(app).call(request).last
body.should.equal [test_body]
end
+
+ specify "should not change anything if there is no Content-Type header" do
+ test_body = '<html><body>404 Not Found</body></html>'
+ app = lambda { |env| [404, {}, [test_body]] }
+ request = Rack::MockRequest.env_for("/", :params => "callback=foo", 'HTTP_ACCEPT' => 'application/json')
+ body = Rack::JSONP.new(app).call(request).last
+ body.should.equal [test_body]
+ end
end

0 comments on commit ea13fab

Please sign in to comment.