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
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,12 @@
|
|||
Mon Oct 18 02:04:11 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
|
||||
|
||||
* 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]
|
||||
|
||||
Sun Oct 17 23:03:48 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
||||
|
||||
* ext/tk/lib/tk/timer.rb: TkTimer#start and restart accept a block
|
||||
|
@ -25,6 +34,7 @@ Sat Oct 16 13:34:56 2004 Kouhei Sutou <kou@cozmixng.org>
|
|||
* lib/rss: supported prety print.
|
||||
* test/rss/test_1.0.rb: added test for calculating default indent size.
|
||||
|
||||
>>>>>>> 1.2673.2.531
|
||||
Fri Oct 15 18:04:35 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
|
||||
|
||||
* ext/tk/lib/tk/timer.rb: TkTimer.new(interval, loop){ ... } is
|
||||
|
|
|
@ -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|
|
||||
|
|
|
@ -90,6 +90,9 @@ module WEBrick
|
|||
@tokens.pop # blocks while no token is there.
|
||||
sock = svr.accept
|
||||
sock.sync = true
|
||||
if @config[:DoNotReverseLookup]
|
||||
sock.do_not_reverse_lookup = true
|
||||
end
|
||||
Utils::set_close_on_exec(sock)
|
||||
th = start_thread(sock, &block)
|
||||
th[:WEBrickThread] = true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue