Search code examples
rubykeep-alivecurb

Is is possible to force curb not use Keep Alive?


Using curb to communicate with some HTTP server and looks like that HTTP server does not implements Keep-Alive properly.

This is why I'm searching way to force curb not use this feature.

Sure, I can sleep minute or so before making next request, but I'd like to do this in other way.


Solution

  • By default, curb uses HTTP 1.1, which gives you keep-alive:

    ?> easy = Curl::Easy.http_get('http://www.yahoo.com')
    => #<Curl::Easy [...]> 
    ?> easy.header_str.grep(/keep-alive/)
    => ["Connection: keep-alive\r\n"]
    

    To prevent keep-alive, force curb to use HTTP 1.0:

    ?> easy = Curl::Easy.http_get('http://www.yahoo.com') { |x| x.version = Curl::HTTP_1_0 }
    => #<Curl::Easy [...]> 
    ?> easy.header_str.grep(/keep-alive/)
    => []