Tuesday, February 4, 2014

Solution to remove Warning "Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true"

While working on Rails 4 application, getting following lines in application log file:

[2014-02-04 20:31:12] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
[2014-02-04 20:31:12] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
[2014-02-04 20:31:12] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true
[2014-02-04 20:31:12] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true



Solution:
Taken from "http://stackoverflow.com/questions/9612618/warn-could-not-determine-content-length-of-response-body-set-content-length-of"

This is a problem of Webrick. you can use "Thin" instead.
Add this to Gemfile
gem 'thin'
then rails s will use thin instead of Webrick, and the warn will disappear.

Solution to turn off Rails asset pipeline log in Rails 4 development log file

While working on one of the application created in Rails4, I was annoyed by the way Rails asset was writing in application log file, debugging was turning out to be bit difficult. Here is how the log was looking like:

Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2014-02-04 20:20:53 +0530
[2014-02-04 20:20:53] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


Started GET "/assets/facebook32x32.png" for 127.0.0.1 at 2014-02-04 20:20:53 +0530
[2014-02-04 20:20:53] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


Started GET "/assets/youtube32x32.png" for 127.0.0.1 at 2014-02-04 20:20:53 +0530
[2014-02-04 20:20:53] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


Started GET "/assets/googleplus.png" for 127.0.0.1 at 2014-02-04 20:20:53 +0530
[2014-02-04 20:20:53] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


Started GET "/assets/twitter-old.png" for 127.0.0.1 at 2014-02-04 20:20:53 +0530
[2014-02-04 20:20:53] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


Started GET "/assets/linkedin32x32.png" for 127.0.0.1 at 2014-02-04 20:20:53 +0530
[2014-02-04 20:20:53] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


Started GET "/assets/banner5.jpeg" for 127.0.0.1 at 2014-02-04 20:20:53 +0530
[2014-02-04 20:20:53] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true


Here is the solution which I implemented to turn off assets pipeline log:

I added 'quiet_assets' gem in Gemfile and then run bundle install:
gem 'quiet_assets', :group => :development 
To re-enable the logging of the asset pipeline messages, place the following in yourconfig/application.rb file:
config.quiet_assets = false