summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorgotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-05-11 07:22:19 +0000
committergotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-05-11 07:22:19 +0000
commit6b957b3ff5bb4bf0d7afdf3ec15e477bc7567aaf (patch)
treef450f83b406adf54c9b9e6e8980221347bd458d5 /lib
parente08694be84818139901d4a0e77606c2925acde54 (diff)
* lib/webrick/cgi.rb: new methods WEBrick::CGI#[], WEBrick::CGI#logger
and WEBrick::CGI#config. (backported from HEAD) * lib/webrick/httputils.rb (WEBrick::HTTPUtils.escape_path): should not use String#split("/"). (backported from HEAD) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8424 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/webrick/cgi.rb26
-rw-r--r--lib/webrick/httputils.rb8
2 files changed, 18 insertions, 16 deletions
diff --git a/lib/webrick/cgi.rb b/lib/webrick/cgi.rb
index 77ae443c20..e795a8b4e2 100644
--- a/lib/webrick/cgi.rb
+++ b/lib/webrick/cgi.rb
@@ -16,6 +16,8 @@ module WEBrick
class CGI
CGIError = Class.new(StandardError)
+ attr_reader :config, :logger
+
def initialize(*args)
if defined?(MOD_RUBY)
unless ENV.has_key?("GATEWAY_INTERFACE")
@@ -26,7 +28,7 @@ module WEBrick
httpv = $1
end
@config = WEBrick::Config::HTTP.dup.update(
- :ServerSoftware => ENV["SERVER_SOFTWARE"],
+ :ServerSoftware => ENV["SERVER_SOFTWARE"] || "null",
:HTTPVersion => HTTPVersion.new(httpv || "1.0"),
:RunOnCGI => true, # to detect if it runs on CGI.
:NPH => false # set true to run as NPH script.
@@ -39,6 +41,10 @@ module WEBrick
@options = args
end
+ def [](key)
+ @config[key]
+ end
+
def start(env=ENV, stdin=$stdin, stdout=$stdout)
sock = WEBrick::CGI::Socket.new(@config, env, stdin, stdout)
req = HTTPRequest.new(@config)
@@ -46,7 +52,7 @@ module WEBrick
unless @config[:NPH] or defined?(MOD_RUBY)
def res.setup_header
unless @header["status"]
- phrase = HTTPStatus::reason_phrase(@status)
+ phrase = HTTPStatus::reason_phrase(@status)
@header["status"] = "#{@status} #{phrase}"
end
super
@@ -58,12 +64,8 @@ module WEBrick
begin
req.parse(sock)
- req.script_name = (env["SCRIPT_NAME"] || "").dup
- if env["PATH_INFO"].nil? || env["PATH_INFO"].empty?
- req.path_info = nil
- else
- req.path_info = env["PATH_INFO"].dup
- end
+ req.script_name = (env["SCRIPT_NAME"] || File.expand_path($0)).dup
+ req.path_info = (env["PATH_INFO"] || "").dup
req.user = env["REMOTE_USER"]
res.request_method = req.request_method
res.request_uri = req.request_uri
@@ -145,11 +147,9 @@ module WEBrick
end
def request_line
- meth = @env["REQUEST_METHOD"]
- url = @env["SCRIPT_NAME"].dup
- if path_info = @env["PATH_INFO"]
- url << path_info
- end
+ meth = @env["REQUEST_METHOD"] || "GET"
+ url = (@env["SCRIPT_NAME"] || File.expand_path($0)).dup
+ url << @env["PATH_INFO"].to_s
url = WEBrick::HTTPUtils.escape_path(url)
if query_string = @env["QUERY_STRING"]
unless query_string.empty?
diff --git a/lib/webrick/httputils.rb b/lib/webrick/httputils.rb
index e0855222f1..67bc281c5d 100644
--- a/lib/webrick/httputils.rb
+++ b/lib/webrick/httputils.rb
@@ -384,9 +384,11 @@ module WEBrick
end
def escape_path(str)
- str.split("/").collect{|i|
- _escape(i, UNESCAPED_PCHAR)
- }.join("/")
+ result = ""
+ str.scan(%r{/([^/]*)}).each{|i|
+ result << "/" << _escape(i[0], UNESCAPED_PCHAR)
+ }
+ return result
end
def escape8bit(str)