Skip to content

Commit

Permalink
Save JSONP-timestamp in env['rack.jsonp.timestamp'] for access from o…
Browse files Browse the repository at this point in the history
…ther middleware and/or app.
  • Loading branch information
grimen committed Feb 23, 2012
1 parent c2001f2 commit f1dc1f3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/rack/jsonp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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
Expand All @@ -25,10 +26,12 @@ def call(env)
# 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)

Expand Down

0 comments on commit f1dc1f3

Please sign in to comment.