summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-11-20 08:07:12 +0800
committerEric Wong <normalperson@yhbt.net>2010-11-20 08:07:12 +0800
commitad268cea66c2b91538dd60fc7f945348bb24214d (patch)
tree74bb792868ce7b4cf4422ffe6096189c14f676dd
parentcd315e5a20b17d29679fb22b4e2ab44cd6d0edeb (diff)
Some apps may do them, so make sure we do them correctly.
-rw-r--r--test/unit/test_stream_input.rb37
-rw-r--r--test/unit/test_tee_input.rb8
2 files changed, 45 insertions, 0 deletions
diff --git a/test/unit/test_stream_input.rb b/test/unit/test_stream_input.rb
index 0c4ec98..f59157a 100644
--- a/test/unit/test_stream_input.rb
+++ b/test/unit/test_stream_input.rb
@@ -153,6 +153,43 @@ class TestStreamInput < Test::Unit::TestCase
     assert_equal '', rv
   end
 
+  def test_gets_read_mix
+    r = init_request("hello\nasdfasdf")
+    si = Unicorn::StreamInput.new(@rd, r)
+    assert_equal "hello\n", si.gets
+    assert_equal "asdfasdf", si.read(9)
+    assert_nil si.read(9)
+  end
+
+  def test_gets_read_mix_chunked
+    r = @parser = Unicorn::HttpParser.new
+    body = "6\r\nhello"
+    @buf = "POST / HTTP/1.1\r\n" \
+           "Host: localhost\r\n" \
+           "Transfer-Encoding: chunked\r\n" \
+           "\r\n#{body}"
+    assert_equal @env, @parser.headers(@env, @buf)
+    assert_equal body, @buf
+    si = Unicorn::StreamInput.new(@rd, r)
+    @wr.syswrite "\n\r\n"
+    assert_equal "hello\n", si.gets
+    @wr.syswrite "8\r\nasdfasdf\r\n"
+    assert_equal"asdfasdf", si.read(9) + si.read(9)
+    @wr.syswrite "0\r\n\r\n"
+    assert_nil si.read(9)
+  end
+
+  def test_gets_read_mix_big
+    r = init_request("hello\n#{'.' * 65536}")
+    si = Unicorn::StreamInput.new(@rd, r)
+    assert_equal "hello\n", si.gets
+    assert_equal '.' * 16384, si.read(16384)
+    assert_equal '.' * 16383, si.read(16383)
+    assert_equal '.' * 16384, si.read(16384)
+    assert_equal '.' * 16385, si.read(16385)
+    assert_nil si.gets
+  end
+
   def init_request(body, size = nil)
     @parser = Unicorn::HttpParser.new
     body = body.to_s.freeze
diff --git a/test/unit/test_tee_input.rb b/test/unit/test_tee_input.rb
index e69c8f1..3766e1f 100644
--- a/test/unit/test_tee_input.rb
+++ b/test/unit/test_tee_input.rb
@@ -267,6 +267,14 @@ class TestTeeInput < Test::Unit::TestCase
     assert_equal "World", @env['HTTP_HELLO']
   end
 
+  def test_gets_read_mix
+    r = init_request("hello\nasdfasdf")
+    ti = Unicorn::TeeInput.new(@rd, r)
+    assert_equal "hello\n", ti.gets
+    assert_equal "asdfasdf", ti.read(9)
+    assert_nil ti.read(9)
+  end
+
 private
 
   def init_request(body, size = nil)