Class: Rack::ContentType
- Inherits:
-
Object
- Object
- Rack::ContentType
- Includes:
- Utils
- Defined in:
- lib/rack/content_type.rb
Overview
Sets the Content-Type header on responses which don’t have one.
Builder Usage:
use Rack::ContentType, "text/plain"
When no content type argument is provided, “text/html” is assumed.
Constant Summary
Constants included from Utils
Utils::DEFAULT_SEP, Utils::ESCAPE_HTML, Utils::ESCAPE_HTML_PATTERN, Utils::HTTP_STATUS_CODES, Utils::Multipart, Utils::PATH_SEPS, Utils::STATUS_WITH_NO_ENTITY_BODY, Utils::SYMBOL_TO_STATUS_CODE
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, content_type = "text/html") ⇒ ContentType
constructor
A new instance of ContentType.
Methods included from Utils
best_q_match, build_nested_query, build_query, byte_ranges, bytesize, clean_path_info, delete_cookie_header!, escape, escape_html, escape_path, normalize_params, params_hash_type?, parse_nested_query, parse_query, q_values, rfc2109, rfc2822, secure_compare, select_best_encoding, set_cookie_header!, status_code, unescape
Constructor Details
#initialize(app, content_type = "text/html") ⇒ ContentType
Returns a new instance of ContentType.
14 15 16 |
# File 'lib/rack/content_type.rb', line 14 def initialize(app, content_type = "text/html") @app, @content_type = app, content_type end |
Instance Method Details
#call(env) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rack/content_type.rb', line 18 def call(env) status, headers, body = @app.call(env) headers = Utils::HeaderHash.new(headers) unless STATUS_WITH_NO_ENTITY_BODY.include?(status) headers[CONTENT_TYPE] ||= @content_type end [status, headers, body] end |