diff options
author | Eric Wong <normalperson@yhbt.net> | 2013-10-18 18:03:51 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-10-18 18:03:51 +0000 |
commit | 3555fdce0c9cf9bb6860a79fdc6843a1e96c9888 (patch) | |
tree | 294bea65cd10359ec3acfd8435db414da595da11 | |
parent | 32998f5d56ada5968139cec91cea289e6ffa52bb (diff) | |
download | yahns-3555fdce0c9cf9bb6860a79fdc6843a1e96c9888.tar.gz |
Some users may wish to disable persistent connections for testing or whatever reason, let them. We'll also be using this feature to force SIGQUIT to expire clients.
-rw-r--r-- | lib/yahns/http_response.rb | 7 | ||||
-rw-r--r-- | test/test_server.rb | 28 |
2 files changed, 32 insertions, 3 deletions
diff --git a/lib/yahns/http_response.rb b/lib/yahns/http_response.rb index 8967670..b6228e5 100644 --- a/lib/yahns/http_response.rb +++ b/lib/yahns/http_response.rb @@ -91,7 +91,8 @@ module Yahns::HttpResponse # :nodoc: status = CODES[status.to_i] || status offset = 0 count = hijack = nil - alive = @hs.next? + k = self.class + alive = @hs.next? && k.persistent_connections if @hs.headers? buf = "#{response_start}#{status}\r\nDate: #{httpdate}\r\n" @@ -126,7 +127,7 @@ module Yahns::HttpResponse # :nodoc: when String buf = rv # hope the skb grows when :wait_writable, :wait_readable - if self.class.output_buffering + if k.output_buffering alive = hijack ? hijack : alive rv = response_header_blocked(rv, buf, body, alive, offset, count) body = nil # ensure we do not close body in ensure @@ -158,7 +159,7 @@ module Yahns::HttpResponse # :nodoc: when String chunk = rv # hope the skb grows when we loop into the trywrite when :wait_writable, :wait_readable - if self.class.output_buffering + if k.output_buffering wbuf = Yahns::Wbuf.new(body, alive) rv = wbuf.wbuf_write(self, chunk) break diff --git a/test/test_server.rb b/test/test_server.rb index 958b4f0..289770d 100644 --- a/test/test_server.rb +++ b/test/test_server.rb @@ -380,4 +380,32 @@ class TestServer < Testcase end [ pid, host, port ] end + + def test_nonpersistent + err = @err + cfg = Yahns::Config.new + host, port = @srv.addr[3], @srv.addr[1] + cfg.instance_eval do + ru = lambda { |_| [ 200, {'Content-Length'=>'2'}, ['HI'] ] } + GTL.synchronize { + app(:rack, ru) { + listen "#{host}:#{port}" + persistent_connections false + } + } + logger(Logger.new(err.path)) + end + srv = Yahns::Server.new(cfg) + pid = fork do + ENV["YAHNS_FD"] = @srv.fileno.to_s + srv.start.join + end + c = TCPSocket.new(host, port) + c.write("GET / HTTP/1.1\r\nHost: example.com\r\n\r\n") + buf = Timeout.timeout(10) { c.read } + assert_match(/Connection: close/, buf) + c.close + ensure + quit_wait(pid) + end end |