Setup is: Puma: 2.9.1 Rails: 4.1.5 Rack: 1.5.2
As per documentation i tried to get ContentLength header working by adding fallowing to my application.rb
config.middleware.use Rack::ContentLength
Unfortunately response was still chunked. After some investingation i found following condition in Rack::ContentLength class:
if !STATUS_WITH_NO_ENTITY_BODY.include?(status.to_i) &&
!headers['Content-Length'] &&
!headers['Transfer-Encoding'] &&
body.respond_to?(:to_ary)
body.respond_to?(:to_ary) is only one which yields false. At that context body is instance of Rack::BodyProxy in which responds_to? is overriden:
def respond_to?(*args)
return false if args.first.to_s =~ /^to_ary$/
super or @body.respond_to?(*args)
end
I am really confused here. Removing body.respond_to?(:to_ary) resolves issue, but i dont feel safe just removing chunks of code from rack lib. Any help getting content-length header working are appreciated. Thanks.