aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-01-24 16:48:52 +0000
committergotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-01-24 16:48:52 +0000
commit327182cada3e0873b0c05118ac533f39eb089121 (patch)
tree8b02d496c4c3ca24b060bf5cac4ac46c6c597b1c
parent57e7333eea5a5280b532d885b3159ecedf3e1c9c (diff)
downloadruby-327182cada3e0873b0c05118ac533f39eb089121.tar.gz
* 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
-rw-r--r--ChangeLog11
-rw-r--r--lib/webrick/httpserver.rb22
2 files changed, 30 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 6883662e4c..57f4f22ba4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/lib/webrick/httpserver.rb b/lib/webrick/httpserver.rb
index 11227cf517..7851ebe201 100644
--- a/lib/webrick/httpserver.rb
+++ b/lib/webrick/httpserver.rb
@@ -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|