123456789_123456789_123456789_123456789_123456789_

Class: Rack::ContentType

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, Utils
Inherits: Object
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 the default.

Constant Summary

Utils - Included

COMMON_SEP, DEFAULT_SEP, HTTP_STATUS_CODES, InvalidParameterError, KeySpaceConstrainedParams, NULL_BYTE, OBSOLETE_SYMBOLS_TO_STATUS_CODES, OBSOLETE_SYMBOL_MAPPINGS, PATH_SEPS, ParameterTypeError, ParamsTooDeepError, STATUS_WITH_NO_ENTITY_BODY, SYMBOL_TO_STATUS_CODE

Class Method Summary

Instance Method Summary

Utils - Included

#best_q_match

Return best accept value to use, based on the algorithm in RFC 2616 Section 14.

#build_nested_query, #build_query,
#byte_ranges

Parses the “Range:” header, if present, into an array of Range objects.

#clean_path_info,
#clock_time

:nocov:

#delete_cookie_header!,
#delete_set_cookie_header

Generate an encoded string based on the given key and value using set_cookie_header for the purpose of causing the specified cookie to be deleted.

#delete_set_cookie_header!

Set an expired cookie in the specified headers with the given cookie key and value using delete_set_cookie_header.

#escape

URI escapes.

#escape_path

Like URI escaping, but with %20 instead of +.

#forwarded_values, #get_byte_ranges,
#parse_cookies

Parse cookies from the provided request environment using parse_cookies_header.

#parse_cookies_header

Parse cookies from the provided header value according to RFC6265.

#parse_nested_query, #parse_query, #q_values, #rfc2822,
#secure_compare

Constant time string comparison.

#select_best_encoding,
#set_cookie_header

Generate an encoded string using the provided key and value suitable for the set-cookie header according to RFC6265.

#set_cookie_header!

Append a cookie in the specified headers with the given cookie key and value using set_cookie_header.

#status_code,
#unescape

Unescapes a URI escaped string with encoding.

#unescape_path

Unescapes the path component of a URI.

#valid_path?

Constructor Details

.new(app, content_type = "text/html") ⇒ ContentType

[ GitHub ]

  
# File 'lib/rack/content_type.rb', line 18

def initialize(app, content_type = "text/html")
  @app = app
  @content_type = content_type
end

Instance Method Details

#call(env)

[ GitHub ]

  
# File 'lib/rack/content_type.rb', line 23

def call(env)
  status, headers, _ = response = @app.call(env)

  unless STATUS_WITH_NO_ENTITY_BODY.key?(status.to_i)
    headers[CONTENT_TYPE] ||= @content_type
  end

  response
end