Method: Rack::JSONP#call

Defined in:
lib/rack/contrib/jsonp.rb

#call(env) ⇒ Object

Proxies the request to the application, stripping out the JSON-P callback method and padding the response with the appropriate callback format.

Changes nothing if no callback param is specified.



18
19
20
21
22
23
24
25
26
# File 'lib/rack/contrib/jsonp.rb', line 18

def call(env)
  status, headers, response = @app.call(env)
  request = Rack::Request.new(env)
  if request.params.include?('callback')
    response = pad(request.params.delete('callback'), response)
    headers['Content-Length'] = response.length.to_s
  end
  [status, headers, response]
end