summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-10-17 17:10:56 +0000
committergotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-10-17 17:10:56 +0000
commitf93f318f77033b97992475bf7d741245ec4ffa2d (patch)
tree893efa17a96405f659c152cebb8777789a823d92
parent51043a36b40eab1e9d6214faf80fe7b8d48cb843 (diff)
* 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
-rw-r--r--ChangeLog10
-rw-r--r--lib/webrick/httpserver.rb33
-rw-r--r--lib/webrick/server.rb3
3 files changed, 42 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 5f7f7d5147..61b9be3e49 100644
--- a/ChangeLog
+++ b/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
diff --git a/lib/webrick/httpserver.rb b/lib/webrick/httpserver.rb
index 11227cf517..ffbae70409 100644
--- a/lib/webrick/httpserver.rb
+++ b/lib/webrick/httpserver.rb
@@ -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|
diff --git a/lib/webrick/server.rb b/lib/webrick/server.rb
index 93e3b2ccf5..0668e27b05 100644
--- a/lib/webrick/server.rb
+++ b/lib/webrick/server.rb
@@ -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