tags:

views:

266

answers:

2

Does anyone know if there is a way to prevent sinatra from sending the 'Connection: close' header in its responses?

To be clear, I have a very simple

get '/path' do
  puts "Some (~200 byte long) string"
end

But on putting the output through a network analyser I see its sending the Connection: close header straight after the HTTP/1.1 200 OK, this I'd like to stop!

A: 

I don't speak Ruby at all, and the Sinatra site isn't terribly clear on what it is (is it a framework for Ruby?) so I might be completely off my rocker here, but:

Connection: close is sent by your Web server when keep alives are turned off. For scalability reasons, keep alives are generally considered to be step one on things to turn off in your server. To be fair, there's a school of thought both ways, particularly when Ajax is involved.

I use nginx for my Django work (I'm thinking it's similar), and I have keep-alives turned off in nginx like this:

14:58 jsmith@lateralus% grep alive /etc/nginx/nginx.conf                            ~
     keepalive_timeout 0;

Apache uses KeepAlive (see here).

If Sinatra is its own Web server, I can't find any documentation to turn keep alives on, and I'll go ahead and eat the fact that I look like an idiot.

Jed Smith
No idiots here trust me, its supposed to be very simple to use but I just can't seem to figure it out! Sinatra is a framework that can run on any number of servers, I'm currently using it with mongrel (built into Ruby) so I guess I need to go there and hunt down some answers!
JP
@JP: Then yes, look for information on keep alives in Mongrel's documentation. I'm looking now and I'll revise the answer if I find something.
Jed Smith
+1  A: 

Ah ha! It seems Mongrel, the server my Sinatra app was running on, doesn't support Keep-Alive. so I just did:

set :server, 'thin'

after gem install thin and everything seems to be working better!

JP
There you go. :)
Jed Smith