lib/goliath/rack/formatters/json.rb in goliath-0.9.1 vs lib/goliath/rack/formatters/json.rb in goliath-0.9.2

- old
+ new

@@ -7,27 +7,12 @@ # encoder that is right for your project. # # @example # use Goliath::Rack::Formatters::JSON class JSON - # Called by the framework to create the formatter. - # - # @return [Goliath::Rack::Formatters::JSON] The JSON formatter. - def initialize(app) - @app = app - end + include AsyncMiddleware - def call(env) - async_cb = env['async.callback'] - env['async.callback'] = Proc.new do |status, headers, body| - async_cb.call(post_process(status, headers, body)) - end - - status, headers, body = @app.call(env) - post_process(status, headers, body) - end - - def post_process(status, headers, body) + def post_process(env, status, headers, body) if json_response?(headers) body = [MultiJson.encode(body)] end [status, headers, body] end