Class: Goliath::Rack::JSONP
- Inherits:
-
Object
- Object
- Goliath::Rack::JSONP
- Includes:
- AsyncMiddleware
- Defined in:
- lib/goliath/rack/jsonp.rb
Overview
A middleware to wrap the response into a JSONP callback.
Instance Method Summary (collapse)
Methods included from AsyncMiddleware
Constructor Details
This class inherits a constructor from Goliath::Rack::AsyncMiddleware
Instance Method Details
- (Object) post_process(env, status, headers, body)
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/goliath/rack/jsonp.rb', line 11 def post_process(env, status, headers, body) return [status, headers, body] unless env.params['callback'] response = "" if body.respond_to?(:each) body.each { |s| response << s } else response = body end [status, headers, ["#{env.params['callback']}(#{response})"]] end |