* lib/webrick/httpserver.rb (WEBrick::HTTPServer#run): support

virtual host.

* lib/webrick/httpserver.rb (WEBrick::HTTPServer#virtual_host): add
  new method to register virtual hosting server.

* lib/webrick/httpserver.rb (WEBrick::HTTPServer#lookup_server): add
  new method to lookup virtual hosting server.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5546 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
gotoyuzo 2004-01-24 16:48:52 +00:00
Родитель 57e7333eea
Коммит 327182cada
2 изменённых файлов: 30 добавлений и 3 удалений

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

@ -1,3 +1,14 @@
Sun Jan 25 01:45:38 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/httpserver.rb (WEBrick::HTTPServer#run): support
virtual host.
* lib/webrick/httpserver.rb (WEBrick::HTTPServer#virtual_host): add
new method to register virtual hosting server.
* lib/webrick/httpserver.rb (WEBrick::HTTPServer#lookup_server): add
new method to lookup virtual hosting server.
Sat Jan 24 13:06:26 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_x509hame.c (ossl_x509name_initialize): change

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

@ -36,22 +36,26 @@ module WEBrick
[ $stderr, AccessLog::REFERER_LOG_FORMAT ]
]
end
@virtual_hosts = Array.new
end
def run(sock)
while true
res = HTTPResponse.new(@config)
req = HTTPRequest.new(@config)
server = self
begin
req.parse(sock)
res.request_method = req.request_method
res.request_uri = req.request_uri
res.request_http_version = req.http_version
res.keep_alive = req.keep_alive?
if handler = @config[:RequestHandler]
server = lookup_server(req) || self
if handler = server[:RequestHandler]
handler.call(req, res)
end
service(req, res)
server.service(req, res)
rescue HTTPStatus::EOFError, HTTPStatus::RequestTimeout => ex
res.set_error(ex)
rescue HTTPStatus::Error => ex
@ -65,7 +69,7 @@ module WEBrick
if req.request_line
req.fixup()
res.send_response(sock)
access_log(@config, req, res)
server.access_log(@config, req, res)
end
end
break if @http_version < "1.1"
@ -121,6 +125,18 @@ module WEBrick
end
end
def virtual_host(server)
@virtual_hosts << server
end
def lookup_server(req)
@virtual_hosts.find{|server|
(server[:Port].nil? || req.port == server[:Port]) &&
(server[:BindAddress].nil? || req.addr[3] == server[:BindAddress]) &&
(server[:ServerName].nil? || req.host == server[:ServerName])
}
end
def access_log(config, req, res)
param = AccessLog::setup_params(config, req, res)
@config[:AccessLog].each{|logger, fmt|