Sets the Content-Length header on responses with fixed-length bodies.
# File lib/rack/content_length.rb, line 12 12: def call(env) 13: status, headers, body = @app.call(env) 14: headers = HeaderHash.new(headers) 15: 16: if !STATUS_WITH_NO_ENTITY_BODY.include?(status.to_i) && 17: !headers['Content-Length'] && 18: !headers['Transfer-Encoding'] && 19: (body.respond_to?(:to_ary) || body.respond_to?(:to_str)) 20: 21: body = [body] if body.respond_to?(:to_str) # rack 0.4 compat 22: length = body.to_ary.inject(0) { |len, part| len + bytesize(part) } 23: headers['Content-Length'] = length.to_s 24: end 25: 26: [status, headers, body] 27: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.