4 # Sets the Content-Length header on responses with fixed-length bodies.
13 status
, headers
, body
= @app.call(env)
14 headers
= HeaderHash
.new(headers
)
16 if !STATUS_WITH_NO_ENTITY_BODY
.include?(status
) &&
17 !headers
['Content-Length'] &&
18 !headers
['Transfer-Encoding'] &&
19 (body
.respond_to
?(:to_ary) || body
.respond_to
?(:to_str))
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
26 [status
, headers
, body
]