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

* lib/webrick/config.rb (WEBrick::Config::HTTP): rename :RequestHander

to :RequestCallback and add new option :ServerAlias.

* lib/webrick/httpserver.rb (WEBrick::HTTPServer#run): use
  :RequestCallback and warn if :RequestHandler is in server's option.

* lib/webrick/httpserver.rb (WEBrick::HTTPServer#run): should print
  error message for WEBrick::HTTPSataus::Error.

* lib/webrick/httpserver.rb (WEBrick::HTTPServer#lookup_server):
  lookup for hostname from :ServerAlias if the req.host is not match
  to :ServerName.

* lib/webrick/httpservlet.rb (WEBrick::HTTPServlet::CGIHandler#do_GET):
  use $?.exitstatus and refine log message.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5917 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
gotoyuzo 2004-03-07 16:06:43 +00:00
parent 4774e8fda5
commit 9b11fc8032
4 changed files with 35 additions and 11 deletions

View file

@ -1,3 +1,21 @@
Mon Mar 8 01:05:55 2004 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/config.rb (WEBrick::Config::HTTP): rename :RequestHander
to :RequestCallback and add new option :ServerAlias.
* lib/webrick/httpserver.rb (WEBrick::HTTPServer#run): use
:RequestCallback and warn if :RequestHandler is in server's option.
* lib/webrick/httpserver.rb (WEBrick::HTTPServer#run): should print
error message for WEBrick::HTTPSataus::Error.
* lib/webrick/httpserver.rb (WEBrick::HTTPServer#lookup_server):
lookup for hostname from :ServerAlias if the req.host is not match
to :ServerName.
* lib/webrick/httpservlet.rb (WEBrick::HTTPServlet::CGIHandler#do_GET):
use $?.exitstatus and refine log message.
Sun Mar 7 16:22:26 2004 WATANABE Hirofumi <eban@ruby-lang.org> Sun Mar 7 16:22:26 2004 WATANABE Hirofumi <eban@ruby-lang.org>
* Makefile.in (lex.c): use $? instead of $<. * Makefile.in (lex.c): use $? instead of $<.

View file

@ -45,14 +45,14 @@ module WEBrick
:DirectoryIndex => ["index.html","index.htm","index.cgi","index.rhtml"], :DirectoryIndex => ["index.html","index.htm","index.cgi","index.rhtml"],
:DocumentRoot => nil, :DocumentRoot => nil,
:DocumentRootOptions => { :FancyIndexing => true }, :DocumentRootOptions => { :FancyIndexing => true },
:RequestCallback => nil,
:ServerAlias => nil,
:RequestHandler => nil, # for HTTPProxyServer
:ProxyAuthProc => nil, :ProxyAuthProc => nil,
:ProxyContentHandler => nil, :ProxyContentHandler => nil,
:ProxyVia => true, :ProxyVia => true,
:ProxyTimeout => true, :ProxyTimeout => true,
# upstream proxy server
:ProxyURI => nil, :ProxyURI => nil,
:CGIInterpreter => nil, :CGIInterpreter => nil,

View file

@ -52,13 +52,18 @@ module WEBrick
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?
server = lookup_server(req) || self server = lookup_server(req) || self
if handler = server[:RequestHandler] if callback = server[:RequestCallback]
handler.call(req, res) callback.call(req, res)
elsif callback = server[:RequestHandler]
msg = ":RequestHandler is deprecated, please use :RequestCallback"
@logger.warn(msg)
callback.call(req, res)
end end
server.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
@logger.error(ex.message)
res.set_error(ex) res.set_error(ex)
rescue HTTPStatus::Status => ex rescue HTTPStatus::Status => ex
res.status = ex.code res.status = ex.code
@ -130,10 +135,11 @@ module WEBrick
end end
def lookup_server(req) def lookup_server(req)
@virtual_hosts.find{|server| @virtual_hosts.find{|s|
(server[:Port].nil? || req.port == server[:Port]) && (s[:Port].nil? || req.port == s[:Port]) &&
(server[:BindAddress].nil? || req.addr[3] == server[:BindAddress]) && (s[:BindAddress].nil? || req.addr[3] == s[:BindAddress]) &&
(server[:ServerName].nil? || req.host == server[:ServerName]) ((s[:ServerName].nil? || req.host == s[:ServerName]) ||
(s[:ServerAlias].nil? || s[:ServerAlias].find{|h| h === req.host}))
} }
end end

View file

@ -55,7 +55,7 @@ module WEBrick
end end
ensure ensure
cgi_in.close cgi_in.close
status = $? >> 8 status = $?.exitstatus
sleep 0.1 if /mswin/ =~ RUBY_PLATFORM sleep 0.1 if /mswin/ =~ RUBY_PLATFORM
data = cgi_out.read data = cgi_out.read
cgi_out.close(true) cgi_out.close(true)
@ -74,7 +74,7 @@ module WEBrick
data = "" unless data data = "" unless data
raw_header, body = data.split(/^[\xd\xa]+/on, 2) raw_header, body = data.split(/^[\xd\xa]+/on, 2)
raise HTTPStatus::InternalServerError, raise HTTPStatus::InternalServerError,
"The server encontered a script error." if body.nil? "Premature end of script headers: #{@script_filename}" if body.nil?
begin begin
header = HTTPUtils::parse_header(raw_header) header = HTTPUtils::parse_header(raw_header)