Class: SpreeApiContentTypeRewriter::Middleware::ContentTypeRewriter

Inherits:
Object
  • Object
show all
Defined in:
lib/spree_api_content_type_rewriter/middleware/content_type_rewriter.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ContentTypeRewriter

Returns a new instance of ContentTypeRewriter.



4
5
6
# File 'lib/spree_api_content_type_rewriter/middleware/content_type_rewriter.rb', line 4

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
# File 'lib/spree_api_content_type_rewriter/middleware/content_type_rewriter.rb', line 8

def call(env)
  status, headers, response = @app.call(env)
  headers['Content-Type'] = 'application/json' if env['action_dispatch.request.path_parameters'][:format] == 'json'
  [status, headers, response]
end