Module: Hanami::Action::Mime
- Defined in:
- lib/hanami/action/mime.rb
Overview
Mime type API
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Constant Summary collapse
- HTTP_ACCEPT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The key that returns accepted mime types from the Rack env
'HTTP_ACCEPT'.freeze
- CONTENT_TYPE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The header key to set the mime type of the response
'Content-Type'.freeze
- DEFAULT_ACCEPT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The default mime type for an incoming HTTP request
'*/*'.freeze
- DEFAULT_CONTENT_TYPE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The default mime type that is returned in the response
'application/octet-stream'.freeze
- DEFAULT_CHARSET =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The default charset that is returned in the response
'utf-8'.freeze
Class Method Summary collapse
-
.included(base) ⇒ Object
private
Override Ruby’s hook for modules.
Instance Method Summary collapse
-
#charset ⇒ String
The charset that will be automatically set in the response.
-
#charset=(value) ⇒ String
Action charset setter, receives new charset value.
-
#content_type ⇒ String
The content type that will be automatically set in the response.
-
#format ⇒ Symbol
Returns a symbol representation of the content type.
Class Method Details
.included(base) ⇒ Object
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.
Override Ruby’s hook for modules. It includes Mime types logic
53 54 55 56 57 58 |
# File 'lib/hanami/action/mime.rb', line 53 def self.included(base) base.class_eval do extend ClassMethods prepend InstanceMethods end end |
Instance Method Details
#charset ⇒ String
The charset that will be automatically set in the response.
It prefers, in order:
* Explicit set value (see #charset=)
* Default configuration charset
* Default content type
To override the value, use #charset=
268 269 270 |
# File 'lib/hanami/action/mime.rb', line 268 def charset @charset || default_charset || DEFAULT_CHARSET end |
#charset=(value) ⇒ String
Action charset setter, receives new charset value
235 236 237 |
# File 'lib/hanami/action/mime.rb', line 235 def charset=(value) @charset = value end |
#content_type ⇒ String
The content type that will be automatically set in the response.
It prefers, in order:
* Explicit set value (see Hanami::Action::Mime#format=)
* Weighted value from Accept header based on all known MIME Types:
- Custom registered MIME Types (see Hanami::Controller::Configuration#format)
* Configured default content type (see Hanami::Controller::Configuration#default_response_format)
* Hard-coded default content type (see Hanami::Action::Mime::DEFAULT_CONTENT_TYPE)
To override the value, use #format=
207 208 209 210 211 212 213 214 215 216 |
# File 'lib/hanami/action/mime.rb', line 207 def content_type return @content_type unless @content_type.nil? if accept_header? type = content_type_from_accept_header return type if type end default_response_type || default_content_type || DEFAULT_CONTENT_TYPE end |
#format ⇒ Symbol
Returns a symbol representation of the content type.
The framework automatically detects the request mime type, and returns the corresponding format.
However, if this value was explicitly set by ‘#format=`, it will return that value
170 171 172 |
# File 'lib/hanami/action/mime.rb', line 170 def format @format ||= detect_format end |