lib/rack/jsonp.rb in rack-jsonp-1.0.0 vs lib/rack/jsonp.rb in rack-jsonp-1.1.0

- old
+ new

@@ -22,12 +22,13 @@ request = Rack::Request.new(env) callback = request.params.delete(@callback_param) env['QUERY_STRING'] = env['QUERY_STRING'].split("&").delete_if{|param| param =~ /^(_|#{@callback_param})/}.join("&") status, headers, response = @app.call(env) - if callback + if callback && headers['Content-Type'] =~ /json/i response = pad(callback, response) headers['Content-Length'] = response.first.length.to_s + headers['Content-Type'] = 'application/javascript' elsif @carriage_return && headers['Content-Type'] =~ /json/i # add a \n after the response if this is a json (not JSONP) response response = carriage_return(response) headers['Content-Length'] = response.first.length.to_s end \ No newline at end of file