1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@640 19e92222-5c0b-0410-8929-a290d50e31e9
This commit is contained in:
evanweaver 2007-10-11 07:22:37 +00:00
parent e577ab7e62
commit 370a88b2e4
2 changed files with 27 additions and 2 deletions

View file

@ -406,6 +406,7 @@ module Mongrel
@socket = socket @socket = socket
@body = StringIO.new @body = StringIO.new
@status = 404 @status = 404
@reason = HTTP_STATUS_CODES[@status]
@header = HeaderOut.new(StringIO.new) @header = HeaderOut.new(StringIO.new)
@header[Const::DATE] = Time.now.httpdate @header[Const::DATE] = Time.now.httpdate
@body_sent = false @body_sent = false
@ -421,8 +422,9 @@ module Mongrel
# by simple passing "finalize=true" to the start method. By default # by simple passing "finalize=true" to the start method. By default
# all handlers run and then mongrel finalizes the request when they're # all handlers run and then mongrel finalizes the request when they're
# all done. # all done.
def start(status=200, finalize=false) def start(status=200, finalize=false, reason=HTTP_STATUS_CODES[status])
@status = status.to_i @status = status.to_i
@reason = reason
yield @header, @body yield @header, @body
finished if finalize finished if finalize
end end
@ -445,7 +447,7 @@ module Mongrel
def send_status(content_length=@body.length) def send_status(content_length=@body.length)
if not @status_sent if not @status_sent
@header['Content-Length'] = content_length if content_length and @status != 304 @header['Content-Length'] = content_length if content_length and @status != 304
write(Const::STATUS_FORMAT % [@status, HTTP_STATUS_CODES[@status]]) write(Const::STATUS_FORMAT % [@status, @reason])
@status_sent = true @status_sent = true
end end
end end

View file

@ -102,5 +102,28 @@ class ResponseTest < Test::Unit::TestCase
assert io.length > 0, "output didn't have data" assert io.length > 0, "output didn't have data"
assert io.read[-contents.length..-1] == contents, "output doesn't end with file payload" assert io.read[-contents.length..-1] == contents, "output doesn't end with file payload"
end end
def test_response_with_custom_reason
reason = "You made a bad request"
io = StringIO.new
resp = HttpResponse.new(io)
resp.start(400, false, reason) { |head,out| }
resp.finished
io.rewind
assert_match(/.* #{reason}$/, io.readline.chomp, "wrong custom reason phrase")
end
def test_response_with_default_reason
code = 400
io = StringIO.new
resp = HttpResponse.new(io)
resp.start(code) { |head,out| }
resp.finished
io.rewind
assert_match(/.* #{HTTP_STATUS_CODES[code]}$/, io.readline.chomp, "wrong default reason phrase")
end
end end