summaryrefslogtreecommitdiff
path: root/test/webrick
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-07 18:38:39 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-08-07 18:38:39 +0000
commit9dff71ad78bce48d61a5f16a59a9f666ceed6350 (patch)
tree8471468a33aa9d64df734587dd2f4e571d8c490d /test/webrick
parentd5ecd17aeedae091ddda0f1a26c67f9902243ab1 (diff)
* lib/webrick/httpresponse.rb: Allow #body to be an IO-like object
that responds to #readpartial and #read. [ruby-trunk - Feature #8155] * NEWS: NEWS for above * test/webrick/test_httpresponse.rb: Tests for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42427 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/webrick')
-rw-r--r--test/webrick/test_httpresponse.rb89
1 files changed, 89 insertions, 0 deletions
diff --git a/test/webrick/test_httpresponse.rb b/test/webrick/test_httpresponse.rb
index d5d5552..aae4973 100644
--- a/test/webrick/test_httpresponse.rb
+++ b/test/webrick/test_httpresponse.rb
@@ -1,5 +1,6 @@
require "webrick"
require "minitest/autorun"
+require "stringio"
module WEBrick
class TestHTTPResponse < MiniTest::Unit::TestCase
@@ -45,5 +46,93 @@ module WEBrick
assert_equal 0, logger.messages.length
end
+
+ def test_send_body_io
+ body_r, body_w = IO.pipe
+
+ body_w.write 'hello'
+ body_w.close
+
+ @res.body = body_r
+
+ r, w = IO.pipe
+
+ @res.send_body w
+
+ w.close
+
+ assert_equal 'hello', r.read
+ end
+
+ def test_send_body_string
+ @res.body = 'hello'
+
+ r, w = IO.pipe
+
+ @res.send_body w
+
+ w.close
+
+ assert_equal 'hello', r.read
+ end
+
+ def test_send_body_string_io
+ @res.body = StringIO.new 'hello'
+
+ r, w = IO.pipe
+
+ @res.send_body w
+
+ w.close
+
+ assert_equal 'hello', r.read
+ end
+
+ def test_send_body_io_chunked
+ @res.chunked = true
+
+ body_r, body_w = IO.pipe
+
+ body_w.write 'hello'
+ body_w.close
+
+ @res.body = body_r
+
+ r, w = IO.pipe
+
+ @res.send_body w
+
+ w.close
+
+ assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
+ end
+
+ def test_send_body_string_chunked
+ @res.chunked = true
+
+ @res.body = 'hello'
+
+ r, w = IO.pipe
+
+ @res.send_body w
+
+ w.close
+
+ assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
+ end
+
+ def test_send_body_string_io_chunked
+ @res.chunked = true
+
+ @res.body = StringIO.new 'hello'
+
+ r, w = IO.pipe
+
+ @res.send_body w
+
+ w.close
+
+ assert_equal "5\r\nhello\r\n0\r\n\r\n", r.read
+ end
end
end