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