about summary refs log tree commit homepage
path: root/test/test_output_buffering.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_output_buffering.rb')
-rw-r--r--test/test_output_buffering.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/test_output_buffering.rb b/test/test_output_buffering.rb
index b6c7500..029b90c 100644
--- a/test/test_output_buffering.rb
+++ b/test/test_output_buffering.rb
@@ -281,5 +281,47 @@ class TestOutputBuffering < Testcase
     apperr.close! if apperr
     quit_wait(pid)
   end
+
+  def test_hijacked
+    err, cfg, host, port = @err, Yahns::Config.new, @srv.addr[3], @srv.addr[1]
+    cfg.instance_eval do
+      ru = lambda do |e|
+        h = {
+          "Content-Type" => "text/plain",
+          "Content-Length" => "4",
+          "rack.hijack" => proc { |x| x.write("HIHI"); x.close },
+        }
+        body = Object.new
+        def body.each; abort "body#each should not be used"; end
+        [ 200, BigHeader.new(h), body ]
+      end
+      GTL.synchronize do
+        app(:rack, ru) do
+          listen "#{host}:#{port}"
+        end
+      end
+      stderr_path err.path
+    end
+    pid = mkserver(cfg)
+    c = get_tcp_client(host, port)
+    c.write "GET / HTTP/1.0\r\n\r\n"
+    begin
+      sleep 1
+    end while c.nread == 0
+    nr = 0
+    last = nil
+    c.each_line do |line|
+      case line
+      when %r{\AX-} then nr += 1
+      else
+        last = line
+      end
+    end
+    assert_equal NR, nr
+    assert_equal "HIHI", last
+    c.close
+  ensure
+    quit_wait(pid)
+  end
 end if `which curl 2>/dev/null`.strip =~ /curl/ &&
        `which md5sum 2>/dev/null`.strip =~ /md5sum/