lib/rack/jsonp.rb in rack-jsonp-1.2.0 vs lib/rack/jsonp.rb in rack-jsonp-1.2.1
- old
+ new
@@ -5,12 +5,10 @@
#
# Adapted from Flinn Mueller (http://actsasflinn.com/).
#
class JSONP
- VERSION = "1.2.0"
-
def initialize(app, options = {})
@app = app
@carriage_return = options[:carriage_return] || false
@callback_param = options[:callback_param] || 'callback'
end
@@ -28,15 +26,15 @@
env['QUERY_STRING'] = env['QUERY_STRING'].split("&").delete_if{|param| param =~ /^(_|#{@callback_param})=/}.join("&")
status, headers, response = @app.call(env)
if callback && headers['Content-Type'] =~ /json/i
response = pad(callback, response)
- headers['Content-Length'] = response.first.length.to_s
+ headers['Content-Length'] = response.first.bytesize.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
+ headers['Content-Length'] = response.first.bytesize.to_s
end
[status, headers, response]
end
# Pads the response with the appropriate callback format according to the