Class: Apiphobic::Middleware::Converters::ContentType

Inherits:
Object
  • Object
show all
Defined in:
lib/apiphobic/middleware/converters/content_type.rb

Constant Summary collapse

JSON_API_MIME_TYPE_PATTERN =
%r{application/vnd\.api\+json(?=\z|;)}

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ContentType

Returns a new instance of ContentType.



9
10
11
# File 'lib/apiphobic/middleware/converters/content_type.rb', line 9

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/apiphobic/middleware/converters/content_type.rb', line 13

def call(env)
  env['CONTENT_TYPE'] = env['CONTENT_TYPE']
                          .to_s
                          .gsub(JSON_API_MIME_TYPE_PATTERN, 'application/json')

  @app.call(env)
end