mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/webrick/httpserver.rb (WEBrick::HTTPServer#virtual_host): new
method to register virtual hosting servers. * lib/webrick/server.rb (WEBrick::GenericServer#accept): call do_not_reverse_lookup for each socket if :DoNotReverseLookup is set. [ruby-core:02357] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7055 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
51043a36b4
commit
f93f318f77
3 changed files with 42 additions and 4 deletions
|
@ -36,25 +36,30 @@ 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]
|
||||
handler.call(req, res)
|
||||
server = lookup_server(req) || self
|
||||
if callback = server[:RequestCallback] || server[:RequestHandler]
|
||||
callback.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
|
||||
@logger.error(ex.message)
|
||||
res.set_error(ex)
|
||||
rescue HTTPStatus::Status => ex
|
||||
res.status = ex.code
|
||||
|
@ -65,7 +70,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 +126,26 @@ module WEBrick
|
|||
end
|
||||
end
|
||||
|
||||
def virtual_host(server)
|
||||
@virtual_hosts << server
|
||||
@virtual_hosts = @virtual_hosts.sort_by{|s|
|
||||
num = 0
|
||||
num -= 4 if s[:BindAddress]
|
||||
num -= 2 if s[:Port]
|
||||
num -= 1 if s[:ServerName]
|
||||
num
|
||||
}
|
||||
end
|
||||
|
||||
def lookup_server(req)
|
||||
@virtual_hosts.find{|s|
|
||||
(s[:BindAddress].nil? || req.addr[3] == s[:BindAddress]) &&
|
||||
(s[:Port].nil? || req.port == s[:Port]) &&
|
||||
((s[:ServerName].nil? || req.host == s[:ServerName]) ||
|
||||
(!s[:ServerAlias].nil? && s[:ServerAlias].find{|h| h === req.host}))
|
||||
}
|
||||
end
|
||||
|
||||
def access_log(config, req, res)
|
||||
param = AccessLog::setup_params(config, req, res)
|
||||
@config[:AccessLog].each{|logger, fmt|
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue