Parent

Methods

Included Modules

Class Index [+]

Quicksearch

Rack::ContentLength

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

Public Class Methods

new(app) click to toggle source
    # File lib/rack/content_length.rb, line 9
 9:     def initialize(app)
10:       @app = app
11:     end

Public Instance Methods

call(env) click to toggle source
    # File lib/rack/content_length.rb, line 13
13:     def call(env)
14:       status, headers, body = @app.call(env)
15:       headers = HeaderHash.new(headers)
16: 
17:       if !STATUS_WITH_NO_ENTITY_BODY.include?(status.to_i) &&
18:          !headers['Content-Length'] &&
19:          !headers['Transfer-Encoding'] &&
20:          body.respond_to?(:to_ary)
21: 
22:         obody = body
23:         body, length = [], 0
24:         obody.each { |part| body << part; length += bytesize(part) }
25:         obody.close if obody.respond_to?(:close)
26: 
27:         headers['Content-Length'] = length.to_s
28:       end
29: 
30:       [status, headers, body]
31:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.