3

I'm working on a Sinatra app and just started adding cacheing. Some of my files are cached correctly, but I keep seeing this warning when serving an image in the public folder:

WARN: Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true.

I don't understand why I'm getting this warning. Sinatra is serving the file correctly out of the public folder, and it says it defaults this header to the file size.

I'm using the following example settings from the README:

set :static_cache_control => [:public, :max_age => 60]

before do
  cache_control :public, :must_revalidate, :max_age => 60
end

How can I get Sinatra to correctly set the content-length header to the static file's size?

Nathan Long
  • 122,748
  • 97
  • 336
  • 451

2 Answers2

1

Another workaround that removes the offending line from webrick. It's just not that useful:

cd `which ruby`/../../lib/ruby/1.9.1/webrick/ && sed -i '.bak' -e'/logger.warn/d' httpresponse.rb

(you may need to sudo)

Xavier Shay
  • 4,067
  • 1
  • 30
  • 54
-2

Evidently, this message is safe to ignore.

See What does "WARN Could not determine content-length of response body." mean and how to I get rid of it?, or if you prefer to get the reply from the source, see the question posed at https://twitter.com/#!/luislavena/status/108998968859566080 and the answer at https://twitter.com/#!/tenderlove/status/108999110136303617.

A workaround: use thin

If the messages bother you, you can work around it by using thin. Add gem 'thin' to your Gemfile, then start your server using thin:

% bundle install
% rails server thin
Community
  • 1
  • 1
fearless_fool
  • 33,645
  • 23
  • 135
  • 217
  • Was the down vote because I didn't answer the actual question? Fair enough -- I won't do it again, even though I think this was a useful answer... – fearless_fool Aug 13 '12 at 02:40