1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Slight change to make clear what's the body of the HttpResponse

git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@10 19e92222-5c0b-0410-8929-a290d50e31e9
This commit is contained in:
zedshaw 2006-01-28 20:27:34 +00:00
parent 6a5116197a
commit 165cc5d978
2 changed files with 10 additions and 14 deletions

View file

@ -100,32 +100,32 @@ module Mongrel
class HttpResponse
attr_reader :socket
attr_reader :out
attr_reader :body
attr_reader :header
attr_reader :status
attr_writer :status
def initialize(socket)
@socket = socket
@out = StringIO.new
@body = StringIO.new
@status = 404
@header = HeaderOut.new(StringIO.new)
end
def start(status=200)
@status = status
yield @header, @out
yield @header, @body
finished
end
def finished
@header.out.rewind
@out.rewind
@body.rewind
@socket.write("HTTP/1.1 #{@status} #{HTTP_STATUS_CODES[@status]}\r\nContent-Length: #{@out.length}\r\n")
@socket.write("HTTP/1.1 #{@status} #{HTTP_STATUS_CODES[@status]}\r\nContent-Length: #{@body.length}\r\n")
@socket.write(@header.out.read)
@socket.write("\r\n")
@socket.write(@out.read)
@socket.write(@body.read)
end
end

View file

@ -11,11 +11,10 @@ class ResponseTest < Test::Unit::TestCase
resp.status = 200
resp.header["Accept"] = "text/plain"
resp.header["X-Whatever"] = "stuff"
resp.out.write("test")
resp.body.write("test")
resp.finished
out.rewind
puts out.read
assert out.length > 0, "output didn't have data"
end
def test_response_200
@ -26,9 +25,7 @@ class ResponseTest < Test::Unit::TestCase
out.write("tested")
out.write("hello!")
end
io.rewind
puts io.read
assert io.length > 0, "output didn't have data"
end
def test_response_404
@ -40,8 +37,7 @@ class ResponseTest < Test::Unit::TestCase
out.write("NOT FOUND")
end
io.rewind
puts io.read
assert io.length > 0, "output didn't have data"
end
end