Class: Goliath::Rack::Formatters::JSON
- Inherits:
-
Object
- Object
- Goliath::Rack::Formatters::JSON
- Includes:
- AsyncMiddleware
- Defined in:
- lib/goliath/rack/formatters/json.rb
Overview
A JSON formatter. Uses MultiJson so you can use the JSON encoder that is right for your project.
Instance Method Summary collapse
Methods included from AsyncMiddleware
#call, #final_response?, #hook_into_callback_chain, #initialize
Methods included from Validator
Instance Method Details
#json_response?(headers) ⇒ Boolean
21 22 23 |
# File 'lib/goliath/rack/formatters/json.rb', line 21 def json_response?(headers) headers['Content-Type'] =~ %r{^application/((vnd\.api\+)?json|javascript)} end |
#post_process(env, status, headers, body) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/goliath/rack/formatters/json.rb', line 14 def post_process(env, status, headers, body) if json_response?(headers) body = [MultiJson.dump(body)] end [status, headers, body] end |