* lib/webrick/cgi.rb: new methods WEBrick::CGI#[], WEBrick::CGI#logger
and WEBrick::CGI#config. these are necessary to use an instance of WEBrick::CGI as the first argument of HTTPServlet#get_instance. (suggested by Tatsuki Sugiura) * lib/webrick/cgi.rb (WEBrick::CGI#initalize): set a dummy to @config[:ServerSoftware] if SERVER_SOFTWARE environment variable is not given. (WEBrick::CGI#start): req.path_info must be a String. (WEBrick::CGI::Socket#request_line): treat REQUEST_METHOD, PATH_INFO and SCRIPT_NAME to run in console. * lib/webrick/httputils.rb (WEBrick::HTTPUtils.escape_path): should not use String#split("/"). it removes trailing empty path component. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8393 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0e3af10d5e
commit
6d69a240b8
17
ChangeLog
17
ChangeLog
@ -1,3 +1,20 @@
|
|||||||
|
Sat Apr 30 06:57:39 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
|
||||||
|
|
||||||
|
* lib/webrick/cgi.rb: new methods WEBrick::CGI#[], WEBrick::CGI#logger
|
||||||
|
and WEBrick::CGI#config. these are necessary to use an instance of
|
||||||
|
WEBrick::CGI as the first argument of HTTPServlet#get_instance.
|
||||||
|
(suggested by Tatsuki Sugiura)
|
||||||
|
|
||||||
|
* lib/webrick/cgi.rb
|
||||||
|
(WEBrick::CGI#initalize): set a dummy to @config[:ServerSoftware]
|
||||||
|
if SERVER_SOFTWARE environment variable is not given.
|
||||||
|
(WEBrick::CGI#start): req.path_info must be a String.
|
||||||
|
(WEBrick::CGI::Socket#request_line): treat REQUEST_METHOD, PATH_INFO
|
||||||
|
and SCRIPT_NAME to run in console.
|
||||||
|
|
||||||
|
* lib/webrick/httputils.rb (WEBrick::HTTPUtils.escape_path): should
|
||||||
|
not use String#split("/"). it removes trailing empty path component.
|
||||||
|
|
||||||
Thu Apr 28 08:21:51 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Thu Apr 28 08:21:51 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* ruby.c (set_arg0): use also environment variable space for setting
|
* ruby.c (set_arg0): use also environment variable space for setting
|
||||||
|
@ -16,6 +16,8 @@ module WEBrick
|
|||||||
class CGI
|
class CGI
|
||||||
CGIError = Class.new(StandardError)
|
CGIError = Class.new(StandardError)
|
||||||
|
|
||||||
|
attr_reader :config, :logger
|
||||||
|
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
if defined?(MOD_RUBY)
|
if defined?(MOD_RUBY)
|
||||||
unless ENV.has_key?("GATEWAY_INTERFACE")
|
unless ENV.has_key?("GATEWAY_INTERFACE")
|
||||||
@ -26,7 +28,7 @@ module WEBrick
|
|||||||
httpv = $1
|
httpv = $1
|
||||||
end
|
end
|
||||||
@config = WEBrick::Config::HTTP.dup.update(
|
@config = WEBrick::Config::HTTP.dup.update(
|
||||||
:ServerSoftware => ENV["SERVER_SOFTWARE"],
|
:ServerSoftware => ENV["SERVER_SOFTWARE"] || "null",
|
||||||
:HTTPVersion => HTTPVersion.new(httpv || "1.0"),
|
:HTTPVersion => HTTPVersion.new(httpv || "1.0"),
|
||||||
:RunOnCGI => true, # to detect if it runs on CGI.
|
:RunOnCGI => true, # to detect if it runs on CGI.
|
||||||
:NPH => false # set true to run as NPH script.
|
:NPH => false # set true to run as NPH script.
|
||||||
@ -39,6 +41,10 @@ module WEBrick
|
|||||||
@options = args
|
@options = args
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def [](key)
|
||||||
|
@config[key]
|
||||||
|
end
|
||||||
|
|
||||||
def start(env=ENV, stdin=$stdin, stdout=$stdout)
|
def start(env=ENV, stdin=$stdin, stdout=$stdout)
|
||||||
sock = WEBrick::CGI::Socket.new(@config, env, stdin, stdout)
|
sock = WEBrick::CGI::Socket.new(@config, env, stdin, stdout)
|
||||||
req = HTTPRequest.new(@config)
|
req = HTTPRequest.new(@config)
|
||||||
@ -58,12 +64,8 @@ module WEBrick
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
req.parse(sock)
|
req.parse(sock)
|
||||||
req.script_name = (env["SCRIPT_NAME"] || "").dup
|
req.script_name = (env["SCRIPT_NAME"] || File.expand_path($0)).dup
|
||||||
if env["PATH_INFO"].nil? || env["PATH_INFO"].empty?
|
req.path_info = (env["PATH_INFO"] || "").dup
|
||||||
req.path_info = nil
|
|
||||||
else
|
|
||||||
req.path_info = env["PATH_INFO"].dup
|
|
||||||
end
|
|
||||||
req.user = env["REMOTE_USER"]
|
req.user = env["REMOTE_USER"]
|
||||||
res.request_method = req.request_method
|
res.request_method = req.request_method
|
||||||
res.request_uri = req.request_uri
|
res.request_uri = req.request_uri
|
||||||
@ -145,11 +147,9 @@ module WEBrick
|
|||||||
end
|
end
|
||||||
|
|
||||||
def request_line
|
def request_line
|
||||||
meth = @env["REQUEST_METHOD"]
|
meth = @env["REQUEST_METHOD"] || "GET"
|
||||||
url = @env["SCRIPT_NAME"].dup
|
url = (@env["SCRIPT_NAME"] || File.expand_path($0)).dup
|
||||||
if path_info = @env["PATH_INFO"]
|
url << @env["PATH_INFO"].to_s
|
||||||
url << path_info
|
|
||||||
end
|
|
||||||
url = WEBrick::HTTPUtils.escape_path(url)
|
url = WEBrick::HTTPUtils.escape_path(url)
|
||||||
if query_string = @env["QUERY_STRING"]
|
if query_string = @env["QUERY_STRING"]
|
||||||
unless query_string.empty?
|
unless query_string.empty?
|
||||||
|
@ -384,9 +384,11 @@ module WEBrick
|
|||||||
end
|
end
|
||||||
|
|
||||||
def escape_path(str)
|
def escape_path(str)
|
||||||
str.split("/").collect{|i|
|
result = ""
|
||||||
_escape(i, UNESCAPED_PCHAR)
|
str.scan(%r{/([^/]*)}).each{|i|
|
||||||
}.join("/")
|
result << "/" << _escape(i[0], UNESCAPED_PCHAR)
|
||||||
|
}
|
||||||
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
def escape8bit(str)
|
def escape8bit(str)
|
||||||
|
@ -87,4 +87,10 @@ class TestWEBrickHTTPUtils < Test::Unit::TestCase
|
|||||||
assert_equal("//foo/bar baz", unescape_form("/%2Ffoo/bar+baz"))
|
assert_equal("//foo/bar baz", unescape_form("/%2Ffoo/bar+baz"))
|
||||||
assert_equal("/~foo/bar baz", unescape_form("/%7Efoo/bar+baz"))
|
assert_equal("/~foo/bar baz", unescape_form("/%7Efoo/bar+baz"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_escape_path
|
||||||
|
assert_equal("/foo/bar", escape_path("/foo/bar"))
|
||||||
|
assert_equal("/foo/bar/", escape_path("/foo/bar/"))
|
||||||
|
assert_equal("/%25foo/bar/", escape_path("/%foo/bar/"))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -4,7 +4,7 @@ require "webrick/cgi"
|
|||||||
class TestApp < WEBrick::CGI
|
class TestApp < WEBrick::CGI
|
||||||
def do_GET(req, res)
|
def do_GET(req, res)
|
||||||
res["content-type"] = "text/plain"
|
res["content-type"] = "text/plain"
|
||||||
if p = req.path_info
|
if (p = req.path_info) && p.length > 0
|
||||||
res.body = p
|
res.body = p
|
||||||
elsif (q = req.query).size > 0
|
elsif (q = req.query).size > 0
|
||||||
res.body = q.keys.sort.collect{|key|
|
res.body = q.keys.sort.collect{|key|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user