Class Rack::ContentLength
In: lib/rack/content_length.rb
Parent: Object

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

Methods

call   new  

Public Class methods

[Source]

   # File lib/rack/content_length.rb, line 4
4:     def initialize(app)
5:       @app = app
6:     end

Public Instance methods

[Source]

    # File lib/rack/content_length.rb, line 8
 8:     def call(env)
 9:       status, headers, body = @app.call(env)
10:       headers = Utils::HeaderHash.new(headers)
11: 
12:       if !Utils::STATUS_WITH_NO_ENTITY_BODY.include?(status) &&
13:          !headers['Content-Length'] &&
14:          !headers['Transfer-Encoding'] &&
15:          (body.respond_to?(:to_ary) || body.respond_to?(:to_str))
16: 
17:         body = [body] if body.respond_to?(:to_str) # rack 0.4 compat
18:         length = body.to_ary.inject(0) { |len, part| len + part.length }
19:         headers['Content-Length'] = length.to_s
20:       end
21: 
22:       [status, headers, body]
23:     end

[Validate]