Feature #8155 ยป webrick.httpresponse.stringio.patch
lib/webrick/httpresponse.rb (working copy) | ||
---|---|---|
# Sends the body on +socket+
|
||
def send_body(socket) # :nodoc:
|
||
case @body
|
||
when IO then send_body_io(socket)
|
||
else send_body_string(socket)
|
||
if @body.respond_to? :readpartial then
|
||
send_body_io(socket)
|
||
else
|
||
send_body_string(socket)
|
||
end
|
||
end
|
||
test/webrick/test_httpresponse.rb (working copy) | ||
---|---|---|
require "webrick"
|
||
require "minitest/autorun"
|
||
require "stringio"
|
||
module WEBrick
|
||
class TestHTTPResponse < MiniTest::Unit::TestCase
|
||
... | ... | |
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
|