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