From 01cef69c94033ecc2cb22b209f79deab2b0d55d6 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 29 Oct 2013 02:36:06 +0000 Subject: implement client_timeout for streaming inputs We may also return HTTP 408 errors in this case. --- test/test_input.rb | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 test/test_input.rb (limited to 'test') diff --git a/test/test_input.rb b/test/test_input.rb new file mode 100644 index 0000000..608ff23 --- /dev/null +++ b/test/test_input.rb @@ -0,0 +1,52 @@ +# Copyright (C) 2013, Eric Wong and all contributors +# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt) +require_relative 'server_helper' +require 'digest/md5' + +class TestInput < Testcase + ENV["N"].to_i > 1 and parallelize_me! + include ServerHelper + alias setup server_helper_setup + alias teardown server_helper_teardown + + MD5 = lambda do |e| + input = e["rack.input"] + buf = "" + md5 = Digest::MD5.new + while input.read(16384, buf) + md5 << buf + end + body = md5.hexdigest + h = { "Content-Length" => body.size.to_s, "Content-Type" => 'text/plain' } + [ 200, h, [body] ] + end + + def test_input_timeout_lazybuffer + stream_input_timeout(:lazy) + end + + def test_input_timeout_nobuffer + stream_input_timeout(false) + end + + def stream_input_timeout(ibtype) + err, cfg, host, port = @err, Yahns::Config.new, @srv.addr[3], @srv.addr[1] + cfg.instance_eval do + GTL.synchronize do + app(:rack, MD5) do + listen "#{host}:#{port}" + input_buffering ibtype + client_timeout 1 + end + end + stderr_path err.path + end + pid = mkserver(cfg) + c = get_tcp_client(host, port) + c.write "PUT / HTTP/1.1\r\nContent-Length: 666\r\n\r\n" + assert_equal c, c.wait(6) + Timeout.timeout(30) { assert_match %r{HTTP/1\.1 408 }, c.read } + ensure + quit_wait(pid) + end +end -- cgit v1.2.3-24-ge0c7