Say your client app consumes only not chunked content (”Transfer-Encoding: chunked” header should not be present) and it requires Content-Length header strictly. How could you achieve that?
Firstly you should set RACK_ENV variable to ‘none’ whether in your deploy.rb file (if you use Capistrano for running Unicorn on staging/production) or just run unicorn_rails prepending with RACK_ENV=none. Here’s the line for the Capistrano’s deploy.rb
set :rack_env, :none
By specifying that Unicorn’s Rack::Builder will use only your app’s middlewares and wouldn’t add Rack::Chunked and Rack::ContentLength ( please see https://github.com/defunkt/unicorn/blob/master/lib/unicorn.rb#L60)
Ok, so how to add Content-Length header to server’s response then?
That’s pretty simple: just add
config.middleware.use Rack::ContentLength
to config/environments/environment_file.rb
That’s it! Thanks!
Leave a Reply