Module: Lotus::Action::Mime
- Defined in:
- lib/lotus/action/mime.rb
Overview
Mime type API
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- HTTP_ACCEPT =
The key that returns accepted mime types from the Rack env
'HTTP_ACCEPT'.freeze
- CONTENT_TYPE =
The header key to set the mime type of the response
'Content-Type'.freeze
- DEFAULT_ACCEPT =
The default mime type for an incoming HTTP request
'*/*'.freeze
- DEFAULT_CONTENT_TYPE =
The default mime type that is returned in the response
'application/octet-stream'.freeze
Class Method Summary collapse
Instance Method Summary collapse
-
#accept?(mime_type) ⇒ Boolean
protected
Match the given mime type with the Accept header.
-
#content_type ⇒ String
protected
The content type that will be automatically set in the response.
-
#content_type=(content_type) ⇒ void
protected
Sets the given content type.
-
#finish ⇒ Object
protected
private
Finalize the response by setting the current content type.
Class Method Details
.included(base) ⇒ Object
29 30 31 32 33 |
# File 'lib/lotus/action/mime.rb', line 29 def self.included(base) base.class_eval do extend ClassMethods end end |
Instance Method Details
#accept?(mime_type) ⇒ Boolean (protected)
Match the given mime type with the Accept header
172 173 174 175 176 |
# File 'lib/lotus/action/mime.rb', line 172 def accept?(mime_type) !!::Rack::Utils.q_values(accept).find do |mime, _| ::Rack::Mime.match?(mime_type, mime) end end |
#content_type ⇒ String (protected)
The content type that will be automatically set in the response.
It prefers, in order:
* Explicit set value (see #content_type=)
* Weighted value from Accept
* Default content type
To override the value, use #content_type=
139 140 141 |
# File 'lib/lotus/action/mime.rb', line 139 def content_type @content_type || accepts || DEFAULT_CONTENT_TYPE end |
#content_type=(content_type) ⇒ void (protected)
This method returns an undefined value.
Sets the given content type
Lotus::Action sets the proper content type automatically, this method
is designed to override that value.
108 109 110 |
# File 'lib/lotus/action/mime.rb', line 108 def content_type=(content_type) @content_type = content_type end |
#finish ⇒ Object (protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Finalize the response by setting the current content type
80 81 82 83 |
# File 'lib/lotus/action/mime.rb', line 80 def finish super headers.merge! CONTENT_TYPE => content_type end |