lib/rack/jsonp.rb in rack-jsonp-1.3.0 vs lib/rack/jsonp.rb in rack-jsonp-1.3.1
- old
+ new
@@ -9,10 +9,11 @@
def initialize(app, options = {})
@app = app
@carriage_return = options[:carriage_return] || false
@callback_param = options[:callback_param] || 'callback'
+ @timestamp_param = options[:timestamp_param] || '_'
end
# Proxies the request to the application, stripping out the JSON-P
# callback method and padding the response with the appropriate callback
# format.
@@ -23,12 +24,15 @@
# remove the callback and _ parameters BEFORE calling the backend, so
# that caching middleware does not store a copy for each value of the
# callback parameter
request = Rack::Request.new(env)
callback = request.params.delete(@callback_param)
+ timestamp = request.params.delete(@timestamp_param)
env['QUERY_STRING'] = env['QUERY_STRING'].split("&").delete_if{|param|
- param =~ /^(_|#{@callback_param})=/
+ param =~ /^(#{@timestamp_param}|#{@callback_param})=/
}.join("&")
+ env['rack.jsonp.callback'] = callback
+ env['rack.jsonp.timestamp'] = timestamp
status, headers, response = @app.call(env)
if callback && headers['Content-Type'] =~ /json/i
response = pad(callback, response)