123456789_123456789_123456789_123456789_123456789_

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

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) ⇒ ContentLength

[ GitHub ]

  
# 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