* lib/webrick/cgi.rb (WEBrick::CGI::Socket#eof?): added lacked method.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18678 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
gotoyuzo 2008-08-17 17:33:13 +00:00
Родитель 0ff4061ef7
Коммит d4835a2703
3 изменённых файлов: 34 добавлений и 3 удалений

Просмотреть файл

@ -1,3 +1,7 @@
Mon Aug 18 02:25:11 2008 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/cgi.rb (WEBrick::CGI::Socket#eof?): added lacked method.
Sun Aug 17 21:50:22 2008 Tanaka Akira <akr@fsij.org> Sun Aug 17 21:50:22 2008 Tanaka Akira <akr@fsij.org>
* io.c (prepare_getline_args): io.gets(10,nil) should cause TypeError. * io.c (prepare_getline_args): io.gets(10,nil) should cause TypeError.

Просмотреть файл

@ -207,6 +207,10 @@ module WEBrick
def each def each
input.each{|line| yield(line) } input.each{|line| yield(line) }
end end
def eof?
input.eof?
end
def <<(data) def <<(data)
@out_port << data @out_port << data

Просмотреть файл

@ -3,9 +3,9 @@ require File.join(File.dirname(__FILE__), "utils.rb")
require "test/unit" require "test/unit"
class TestWEBrickCGI < Test::Unit::TestCase class TestWEBrickCGI < Test::Unit::TestCase
def test_cgi CRLF = "\r\n"
accepted = started = stopped = 0
requested0 = requested1 = 0 def start_cgi_server(&block)
config = { config = {
:CGIInterpreter => TestWEBrick::RubyBin, :CGIInterpreter => TestWEBrick::RubyBin,
:DocumentRoot => File.dirname(__FILE__), :DocumentRoot => File.dirname(__FILE__),
@ -22,6 +22,12 @@ class TestWEBrickCGI < Test::Unit::TestCase
config[:CGIPathEnv] = ENV['PATH'] # runtime dll may not be in system dir. config[:CGIPathEnv] = ENV['PATH'] # runtime dll may not be in system dir.
end end
TestWEBrick.start_httpserver(config){|server, addr, port| TestWEBrick.start_httpserver(config){|server, addr, port|
block.call(server, addr, port)
}
end
def test_cgi
start_cgi_server{|server, addr, port|
http = Net::HTTP.new(addr, port) http = Net::HTTP.new(addr, port)
req = Net::HTTP::Get.new("/webrick.cgi") req = Net::HTTP::Get.new("/webrick.cgi")
http.request(req){|res| assert_equal("/webrick.cgi", res.body)} http.request(req){|res| assert_equal("/webrick.cgi", res.body)}
@ -75,4 +81,21 @@ class TestWEBrickCGI < Test::Unit::TestCase
} }
} }
end end
def test_bad_request
start_cgi_server{|server, addr, port|
sock = TCPSocket.new(addr, port)
begin
sock << "POST /webrick.cgi HTTP/1.0" << CRLF
sock << "Content-Type: application/x-www-form-urlencoded" << CRLF
sock << "Content-Length: 1024" << CRLF
sock << CRLF
sock << "a=1&a=2&b=x"
sock.close_write
assert_match(%r{\AHTTP/\d.\d 400 Bad Request}, sock.read)
ensure
sock.close
end
}
end
end end