1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
parent 57e7333eea
commit 327182cada
2 changed files with 30 additions and 3 deletions

View file

@ -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> Sat Jan 24 13:06:26 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/ossl_x509hame.c (ossl_x509name_initialize): change * ext/openssl/ossl_x509hame.c (ossl_x509name_initialize): change

View file

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