Class: Rack::ContentTypeDefault
- Inherits:
-
Object
- Object
- Rack::ContentTypeDefault
- Defined in:
- lib/rack/content_type_default.rb,
lib/rack/content_type_default/version.rb
Constant Summary collapse
- VERSION =
'1.1.0'
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, methods = [:post], content_type = 'application/json', paths = 'all', use_path_hint = false) ⇒ ContentTypeDefault
constructor
A new instance of ContentTypeDefault.
Constructor Details
#initialize(app, methods = [:post], content_type = 'application/json', paths = 'all', use_path_hint = false) ⇒ ContentTypeDefault
Returns a new instance of ContentTypeDefault.
8 9 10 11 12 13 14 |
# File 'lib/rack/content_type_default.rb', line 8 def initialize(app, methods = [:post], content_type = 'application/json', paths = 'all', use_path_hint = false) @app = app @methods = [*methods].map { |item| item.to_s.upcase } @content_type = content_type @paths = [*paths] @use_path_hint = use_path_hint end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/rack/content_type_default.rb', line 16 def call(env) req = Rack::Request.new(env) if override_content_type?(req) env['CONTENT_TYPE'] = @use_path_hint ? determine_content_type(req.env['PATH_INFO']) : @content_type end @app.call(env) end |