Class: SafePrettyJson::RackMiddleware
- Inherits:
-
Object
- Object
- SafePrettyJson::RackMiddleware
- Defined in:
- lib/safe_pretty_json/rack_middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ RackMiddleware
constructor
A new instance of RackMiddleware.
Constructor Details
#initialize(app) ⇒ RackMiddleware
Returns a new instance of RackMiddleware.
5 6 7 |
# File 'lib/safe_pretty_json/rack_middleware.rb', line 5 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/safe_pretty_json/rack_middleware.rb', line 9 def call(env) status, headers, response = @app.call(env) if %r{^application\/json}.match?(headers['Content-Type']) prettified = SafePrettyJson.prettify(response.body) response = [prettified] headers['Content-Length'] = prettified.bytesize.to_s end [status, headers, response] end |