summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-06-30 14:15:57 -0700
committerEric Wong <normalperson@yhbt.net>2009-06-30 14:15:57 -0700
commit2d3f12f0ca25ddfdec5b7d92f76489dcc1f26cf7 (patch)
treefb4229b195bbd4241b0708da3edaa894b5ca6600
parent608e6243a2b15bfc28c3524ed45d5fc7598e8565 (diff)
I'd honestly be more comfortable doing this in C (and possibly
adapting the code from the libcurl internals since that code has
been very well-tested).
-rw-r--r--lib/unicorn/chunked_reader.rb3
-rw-r--r--test/unit/test_chunked_reader.rb16
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/unicorn/chunked_reader.rb b/lib/unicorn/chunked_reader.rb
index 40d421d..f9bd4ec 100644
--- a/lib/unicorn/chunked_reader.rb
+++ b/lib/unicorn/chunked_reader.rb
@@ -1,7 +1,8 @@
 # Copyright (c) 2009 Eric Wong
 # You can redistribute it and/or modify it under the same terms as Ruby.
 
-module Unicorn; end
+require 'unicorn'
+require 'unicorn/http11'
 
 module Unicorn
   class ChunkedReader
diff --git a/test/unit/test_chunked_reader.rb b/test/unit/test_chunked_reader.rb
index ec5c68a..6a26c8f 100644
--- a/test/unit/test_chunked_reader.rb
+++ b/test/unit/test_chunked_reader.rb
@@ -1,5 +1,6 @@
 require 'test/unit'
 require 'unicorn'
+require 'unicorn/http11'
 require 'tempfile'
 require 'io/nonblock'
 require 'digest/sha1'
@@ -18,6 +19,21 @@ class TestChunkedReader < Test::Unit::TestCase
     return if $$ != @start_pid
     @rd.close rescue nil
     @wr.close rescue nil
+    begin
+      Process.wait
+    rescue Errno::ECHILD
+      break
+    end while true
+  end
+
+  def test_error
+    cr = bin_reader(@rd, "8\r\nasdfasdf\r\n8\r\nasdfasdfa#{'a' * 1024}")
+    a = nil
+    assert_nothing_raised { a = cr.readpartial(8192) }
+    assert_equal 'asdfasdf', a
+    assert_nothing_raised { a = cr.readpartial(8192) }
+    assert_equal 'asdfasdf', a
+    assert_raises(Unicorn::HttpParserError) { cr.readpartial(8192) }
   end
 
   def test_eof1