summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-01-18 06:03:43 +0000
committergotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-01-18 06:03:43 +0000
commit4281260109874562d78c7f2b6b05a5aacf10afb2 (patch)
tree9e236a812f7161e3f6953126ee67d46bbead3a75
parent1b31bbe2c43ff8569d319d7c8663daabbb0cd029 (diff)
downloadruby-4281260109874562d78c7f2b6b05a5aacf10afb2.tar.gz
ruby-4281260109874562d78c7f2b6b05a5aacf10afb2.tar.xz
ruby-4281260109874562d78c7f2b6b05a5aacf10afb2.zip
* lib/webrick/ssl.rb (WEBrick::Config::SSL): the default value
of :SSLEnable is false. * lib/webrick/server.rb (WEBrick::Daemon.start): prepared stdio don't allow changing its mode. * lib/webrick/httpproxy.rb (WEBrick::HTTPProxyServer#proxy_service): should delete trailing LF from the result of pack("m*"). * lib/webrick/httpproxy.rb (WEBrick::HTTPProxyServer#proxy_connect): - should delete trailing LF from the result of pack("m*"). - clear Request-Line not to send the response by HTTPServer#run. * lib/webrick/httputils (WEBrick::HTTPUtils.parse_qvalues): refine regexp (and change the name of a local variable). * lib/webrick/httputils.rb (WEBrick::HTTPUtils#escape_path): add new method to escape URI path component. * lib/webrick/cgi.rb (WEBrick::CGI::Socket#request_line): should escape SCRIPT_NAME and PATH_INFO before being parsed as a URI. * test/webrick/*, sample/webrick/httpproxy.rb: add new file. git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@7784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog30
-rw-r--r--lib/webrick/cgi.rb1
-rw-r--r--lib/webrick/httpproxy.rb14
-rw-r--r--lib/webrick/httputils.rb25
-rw-r--r--lib/webrick/server.rb6
-rw-r--r--lib/webrick/ssl.rb2
-rw-r--r--test/webrick/test_httpauth.rb29
7 files changed, 65 insertions, 42 deletions
diff --git a/ChangeLog b/ChangeLog
index 363b52b54..21b29b8c5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,29 @@
+Tue Jan 18 15:03:05 2005 GOTOU Yuuzou <gotoyuzo@notwork.org>
+
+ * lib/webrick/ssl.rb (WEBrick::Config::SSL): the default value
+ of :SSLEnable is false.
+
+ * lib/webrick/server.rb (WEBrick::Daemon.start): prepared stdio
+ don't allow changing its mode.
+
+ * lib/webrick/httpproxy.rb (WEBrick::HTTPProxyServer#proxy_service):
+ should delete trailing LF from the result of pack("m*").
+
+ * lib/webrick/httpproxy.rb (WEBrick::HTTPProxyServer#proxy_connect):
+ - should delete trailing LF from the result of pack("m*").
+ - clear Request-Line not to send the response by HTTPServer#run.
+
+ * lib/webrick/httputils (WEBrick::HTTPUtils.parse_qvalues):
+ refine regexp (and change the name of a local variable).
+
+ * lib/webrick/httputils.rb (WEBrick::HTTPUtils#escape_path): add
+ new method to escape URI path component.
+
+ * lib/webrick/cgi.rb (WEBrick::CGI::Socket#request_line): should
+ escape SCRIPT_NAME and PATH_INFO before being parsed as a URI.
+
+ * test/webrick/*, sample/webrick/httpproxy.rb: add new file.
+
Mon Jan 17 23:33:46 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (aix): fix typo. [ruby-talk:126401]
@@ -3544,7 +3570,7 @@ Sun Jun 13 00:23:04 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tcltklib/extconf.rb: [EXPERIMENTAL] MacOS X (darwin) support
* ext/tcltklib/tcltklib.c: fix thread trouble on callback proc, and
- eliminate warning about instance variable access
+ eliminate warning about instance variable access
* ext/tk/lib/tk/menubar.rb: improve supported menu_spec
@@ -3631,7 +3657,7 @@ Thu May 27 23:15:18 2004 NAKAMURA, Hiroshi <nakahiro@sarion.co.jp>
and a cell is represented as just a String or nil(NULL). this
change will cause widespread destruction.
- CSV.open("foo.csv", "r") do |row|
+ CSV.open("foo.csv", "r") do |row|
row.each do |cell|
if cell.is_null # using Cell#is_null
p "(NULL)"
diff --git a/lib/webrick/cgi.rb b/lib/webrick/cgi.rb
index 5c38e42fc..ca81e4b93 100644
--- a/lib/webrick/cgi.rb
+++ b/lib/webrick/cgi.rb
@@ -147,6 +147,7 @@ module WEBrick
if path_info = @env["PATH_INFO"]
url << path_info
end
+ url = WEBrick::HTTPUtils.escape_path(url)
if query_string = @env["QUERY_STRING"]
unless query_string.empty?
url << "?" << query_string
diff --git a/lib/webrick/httpproxy.rb b/lib/webrick/httpproxy.rb
index c5ed44f1d..14e349977 100644
--- a/lib/webrick/httpproxy.rb
+++ b/lib/webrick/httpproxy.rb
@@ -15,6 +15,14 @@ require "net/http"
Net::HTTP::version_1_2 if RUBY_VERSION < "1.7"
module WEBrick
+ NullReader = Object.new
+ class << NullReader
+ def read(*args)
+ nil
+ end
+ alias gets read
+ end
+
class HTTPProxyServer < HTTPServer
def initialize(config)
super
@@ -111,6 +119,7 @@ module WEBrick
proxy_port = proxy.port
if proxy.userinfo
credentials = "Basic " + [proxy.userinfo].pack("m*")
+ credentials.chomp!
header['proxy-authorization'] = credentials
end
end
@@ -171,6 +180,7 @@ module WEBrick
proxy_request_line = "CONNECT #{host}:#{port} HTTP/1.0"
if proxy.userinfo
credentials = "Basic " + [proxy.userinfo].pack("m*")
+ credentials.chomp!
end
host, port = proxy.host, proxy.port
end
@@ -211,6 +221,10 @@ module WEBrick
end
res.send_response(ua)
access_log(@config, req, res)
+
+ # Should clear request-line not to send the sesponse twice.
+ # see: HTTPServer#run
+ req.parse(NullReader) rescue nil
end
begin
diff --git a/lib/webrick/httputils.rb b/lib/webrick/httputils.rb
index 18e3e2588..e0855222f 100644
--- a/lib/webrick/httputils.rb
+++ b/lib/webrick/httputils.rb
@@ -179,14 +179,14 @@ module WEBrick
if value
parts = value.split(/,\s*/)
parts.each {|part|
- if m = %r{^([^\s,]+?)(?:;\s*q=([\d]+(?:\.[\d]+)))?$}.match(part)
- lang = m[1]
+ if m = %r{^([^\s,]+?)(?:;\s*q=(\d+(?:\.\d+)?))?$}.match(part)
+ val = m[1]
q = (m[2] or 1).to_f
- tmp.push([lang, q])
+ tmp.push([val, q])
end
}
- tmp = tmp.sort_by{|lang, q| -q}
- tmp.collect!{|lang, q| lang}
+ tmp = tmp.sort_by{|val, q| -q}
+ tmp.collect!{|val, q| val}
end
return tmp
end
@@ -352,15 +352,18 @@ module WEBrick
unwise = '{}|\\^[]`'
nonascii = (0x80..0xff).collect{|c| c.chr }.join
+ module_function
+
def _make_regex(str) /([#{Regexp.escape(str)}])/n end
+ def _make_regex!(str) /([^#{Regexp.escape(str)}])/n end
def _escape(str, regex) str.gsub(regex){ "%%%02X" % $1[0] } end
def _unescape(str, regex) str.gsub(regex){ $1.hex.chr } end
- module_function :_make_regex, :_escape, :_unescape
UNESCAPED = _make_regex(control+space+delims+unwise+nonascii)
UNESCAPED_FORM = _make_regex(reserved+control+delims+unwise+nonascii)
NONASCII = _make_regex(nonascii)
ESCAPED = /%([0-9a-fA-F]{2})/
+ UNESCAPED_PCHAR = _make_regex!(unreserved+":@&=+$,")
def escape(str)
_escape(str, UNESCAPED)
@@ -380,12 +383,14 @@ module WEBrick
_unescape(str.gsub(/\+/, " "), ESCAPED)
end
+ def escape_path(str)
+ str.split("/").collect{|i|
+ _escape(i, UNESCAPED_PCHAR)
+ }.join("/")
+ end
+
def escape8bit(str)
_escape(str, NONASCII)
end
-
- module_function :escape, :unescape, :escape_form, :unescape_form,
- :escape8bit
-
end
end
diff --git a/lib/webrick/server.rb b/lib/webrick/server.rb
index bc0ad97c8..faa32a5db 100644
--- a/lib/webrick/server.rb
+++ b/lib/webrick/server.rb
@@ -31,9 +31,9 @@ module WEBrick
exit!(0) if fork
Dir::chdir("/")
File::umask(0)
- [ STDIN, STDOUT, STDERR ].each{|io|
- io.reopen("/dev/null", "r+")
- }
+ STDIN.reopen("/dev/null")
+ STDOUT.reopen("/dev/null", "w")
+ STDERR.reopen("/dev/null", "w")
yield if block_given?
end
end
diff --git a/lib/webrick/ssl.rb b/lib/webrick/ssl.rb
index 4562ba494..03bfdf4aa 100644
--- a/lib/webrick/ssl.rb
+++ b/lib/webrick/ssl.rb
@@ -14,7 +14,7 @@ module WEBrick
osslv = ::OpenSSL::OPENSSL_VERSION.split[1]
SSL = {
:ServerSoftware => "#{svrsoft} OpenSSL/#{osslv}",
- :SSLEnable => true,
+ :SSLEnable => false,
:SSLCertificate => nil,
:SSLPrivateKey => nil,
:SSLClientCA => nil,
diff --git a/test/webrick/test_httpauth.rb b/test/webrick/test_httpauth.rb
index 7109ebc2c..75926b162 100644
--- a/test/webrick/test_httpauth.rb
+++ b/test/webrick/test_httpauth.rb
@@ -3,34 +3,11 @@ require "net/http"
require "tempfile"
require "webrick"
require "webrick/httpauth/basicauth"
+require File.join(File.dirname(__FILE__), "utils.rb")
class TestWEBrickHTTPAuth < Test::Unit::TestCase
- class NullWriter
- def NullWriter.<<(msg)
- puts msg if $DEBUG
- return self
- end
- end
-
- def start_httpserver
- server = WEBrick::HTTPServer.new(
- :BindAddress => "0.0.0.0", :Port => 0,
- :Logger => WEBrick::Log.new(NullWriter),
- :AccessLog => [[NullWriter, ""]]
- )
- thread = nil
- begin
- thread = Thread.start{ server.start }
- addr = server.listeners[0].addr
- yield([server, addr[3], addr[1]])
- ensure
- server.stop
- thread.join
- end
- end
-
def test_basic_auth
- start_httpserver{|server, addr, port|
+ TestWEBrick.start_httpserver{|server, addr, port|
realm = "WEBrick's realm"
path = "/basic_auth"
@@ -50,7 +27,7 @@ class TestWEBrickHTTPAuth < Test::Unit::TestCase
end
def test_basic_auth2
- start_httpserver{|server, addr, port|
+ TestWEBrick.start_httpserver{|server, addr, port|
realm = "WEBrick's realm"
path = "/basic_auth2"