Class: Rack::ContentLength

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
rack/rack/content_length.rb

Overview

Sets the Content-Length header on responses with fixed-length bodies.

Constant Summary

Class Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (ContentLength) initialize(app)

Returns a new instance of ContentLength



9
10
11
# File 'rack/rack/content_length.rb', line 9

def initialize(app)
  @app = app
end

Class Attribute Details

+ (void) key_space_limit Originally defined in module Utils

Returns the value of attribute key_space_limit

Instance Method Details

- (void) call(env)



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'rack/rack/content_length.rb', line 13

def call(env)
  status, headers, body = @app.call(env)
  headers = HeaderHash.new(headers)

  if !STATUS_WITH_NO_ENTITY_BODY.include?(status.to_i) &&
     !headers['Content-Length'] &&
     !headers['Transfer-Encoding'] &&
     body.respond_to?(:to_ary)

    obody = body
    body, length = [], 0
    obody.each { |part| body << part; length += bytesize(part) }
    obody.close if obody.respond_to?(:close)

    headers['Content-Length'] = length.to_s
  end

  [status, headers, body]
end