Some of applications need to send content-length header in every request. For example, when sending something to a mobile device – it would be nice to tell this device how much data are we sending, so the mobile user could see real progress bar.

How to do it in Ruby on Rails 3.1? Well, here you have a list of rack middleware. There is one called Rack::ContentLength, which we will be using. To do so, just include following line into application.rb:

config.middleware.use Rack::ContentLength

There is a lot interesting stuff going on in rack middleware. For example you can also see this Railscast for more details.