2008-05-18 17:33:24 +04:00
|
|
|
begin
|
|
|
|
loadpath = $:.dup
|
|
|
|
$:.replace($: | [File.expand_path("../ruby", File.dirname(__FILE__))])
|
|
|
|
require 'envutil'
|
|
|
|
ensure
|
|
|
|
$:.replace(loadpath)
|
|
|
|
end
|
2005-01-07 14:05:22 +03:00
|
|
|
require "webrick"
|
2005-01-10 10:58:55 +03:00
|
|
|
begin
|
|
|
|
require "webrick/https"
|
|
|
|
rescue LoadError
|
|
|
|
end
|
2005-01-07 14:05:22 +03:00
|
|
|
require "webrick/httpproxy"
|
|
|
|
|
|
|
|
module TestWEBrick
|
|
|
|
NullWriter = Object.new
|
|
|
|
def NullWriter.<<(msg)
|
|
|
|
puts msg if $DEBUG
|
|
|
|
return self
|
|
|
|
end
|
|
|
|
|
2008-05-18 17:33:24 +04:00
|
|
|
RubyBin = "\"#{EnvUtil.rubybin}\""
|
|
|
|
RubyBin << " \"-I#{File.expand_path("../..", File.dirname(__FILE__))}/lib\""
|
|
|
|
RubyBin << " \"-I#{File.dirname(EnvUtil.rubybin)}/.ext/common\""
|
|
|
|
RubyBin << " \"-I#{File.dirname(EnvUtil.rubybin)}/.ext/#{RUBY_PLATFORM}\""
|
|
|
|
|
2005-01-07 14:05:22 +03:00
|
|
|
module_function
|
|
|
|
|
|
|
|
def start_server(klass, config={}, &block)
|
|
|
|
server = klass.new({
|
|
|
|
:BindAddress => "127.0.0.1", :Port => 0,
|
2007-12-31 17:17:41 +03:00
|
|
|
:ShutdownSocketWithoutClose =>true,
|
|
|
|
:ServerType => Thread,
|
2005-01-07 14:05:22 +03:00
|
|
|
:Logger => WEBrick::Log.new(NullWriter),
|
|
|
|
:AccessLog => [[NullWriter, ""]]
|
|
|
|
}.update(config))
|
|
|
|
begin
|
2007-12-31 17:17:41 +03:00
|
|
|
server.start
|
2005-01-07 14:05:22 +03:00
|
|
|
addr = server.listeners[0].addr
|
2006-07-01 12:03:18 +04:00
|
|
|
block.yield([server, addr[3], addr[1]])
|
2005-01-07 14:05:22 +03:00
|
|
|
ensure
|
2007-12-31 17:17:41 +03:00
|
|
|
server.shutdown
|
|
|
|
until server.status == :Stop
|
|
|
|
sleep 0.1
|
|
|
|
end
|
2005-01-07 14:05:22 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def start_httpserver(config={}, &block)
|
|
|
|
start_server(WEBrick::HTTPServer, config, &block)
|
|
|
|
end
|
|
|
|
|
|
|
|
def start_httpproxy(config={}, &block)
|
|
|
|
start_server(WEBrick::HTTPProxyServer, config, &block)
|
|
|
|
end
|
|
|
|
end
|