Class: Rack::ContentLength
| Relationships & Source Files | |
| Super Chains via Extension / Inclusion / Inheritance | |
|
Instance Chain:
self,
Utils
|
|
| Inherits: | Object |
| Defined in: | lib/rack/content_length.rb |
Overview
Sets the content-length header on responses that do not specify a content-length or transfer-encoding header. Note that this does not fix responses that have an invalid content-length header specified.
Constant Summary
Utils - Included
ALLOWED_FORWARDED_PARAMS, 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, URI_PARSER, VALID_COOKIE_KEY
Class Method Summary
- .new(app) ⇒ ContentLength constructor
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 |
| #delete_set_cookie_header! | Set an expired cookie in the specified headers with the given cookie |
| #escape | URI escapes. |
| #escape_html | Escape ampersands, brackets and quotes to their HTML/XML entities. |
| #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 |
| #parse_nested_query, #parse_query, #q_values, #rfc2822, | |
| #secure_compare | Constant time string comparison. |
| #select_best_encoding | Given an array of available encoding strings, and an array of acceptable encodings for a request, where each element of the acceptable encodings array is an array where the first element is an encoding name and the second element is the numeric priority for the encoding, return the available encoding with the highest priority. |
| #set_cookie_header | Generate an encoded string using the provided |
| #set_cookie_header! | Append a cookie in the specified headers with the given cookie |
| #status_code, | |
| #unescape | Unescapes a URI escaped string with |
| #unescape_path | Unescapes the path component of a URI. |
| #valid_path? | |
Constructor Details
.new(app) ⇒ ContentLength
# File 'lib/rack/content_length.rb', line 15
def initialize(app) @app = app end
Instance Method Details
#call(env)
[ GitHub ]# File 'lib/rack/content_length.rb', line 19
def call(env) status, headers, body = response = @app.call(env) if !STATUS_WITH_NO_ENTITY_BODY.key?(status.to_i) && !headers[CONTENT_LENGTH] && !headers[TRANSFER_ENCODING] && body.respond_to?(:to_ary) response[2] = body = body.to_ary headers[CONTENT_LENGTH] = body.sum(&:bytesize).to_s end response end