webrick 1.3.1 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of webrick might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/lib/webrick.rb +6 -6
- data/lib/webrick/accesslog.rb +9 -1
- data/lib/webrick/cgi.rb +58 -5
- data/lib/webrick/compat.rb +2 -1
- data/lib/webrick/config.rb +47 -10
- data/lib/webrick/cookie.rb +69 -7
- data/lib/webrick/htmlutils.rb +4 -2
- data/lib/webrick/httpauth.rb +6 -5
- data/lib/webrick/httpauth/authenticator.rb +13 -8
- data/lib/webrick/httpauth/basicauth.rb +16 -8
- data/lib/webrick/httpauth/digestauth.rb +35 -32
- data/lib/webrick/httpauth/htdigest.rb +12 -8
- data/lib/webrick/httpauth/htgroup.rb +10 -6
- data/lib/webrick/httpauth/htpasswd.rb +46 -9
- data/lib/webrick/httpauth/userdb.rb +1 -0
- data/lib/webrick/httpproxy.rb +93 -48
- data/lib/webrick/httprequest.rb +192 -27
- data/lib/webrick/httpresponse.rb +182 -62
- data/lib/webrick/https.rb +90 -2
- data/lib/webrick/httpserver.rb +45 -15
- data/lib/webrick/httpservlet.rb +6 -5
- data/lib/webrick/httpservlet/abstract.rb +5 -6
- data/lib/webrick/httpservlet/cgi_runner.rb +3 -2
- data/lib/webrick/httpservlet/cgihandler.rb +22 -10
- data/lib/webrick/httpservlet/erbhandler.rb +4 -3
- data/lib/webrick/httpservlet/filehandler.rb +136 -65
- data/lib/webrick/httpservlet/prochandler.rb +15 -1
- data/lib/webrick/httpstatus.rb +24 -14
- data/lib/webrick/httputils.rb +132 -13
- data/lib/webrick/httpversion.rb +28 -1
- data/lib/webrick/log.rb +25 -5
- data/lib/webrick/server.rb +234 -74
- data/lib/webrick/ssl.rb +100 -12
- data/lib/webrick/utils.rb +98 -69
- data/lib/webrick/version.rb +6 -1
- metadata +66 -72
- data/README.txt +0 -21
- data/sample/webrick/demo-app.rb +0 -66
- data/sample/webrick/demo-multipart.cgi +0 -12
- data/sample/webrick/demo-servlet.rb +0 -6
- data/sample/webrick/demo-urlencoded.cgi +0 -12
- data/sample/webrick/hello.cgi +0 -11
- data/sample/webrick/hello.rb +0 -8
- data/sample/webrick/httpd.rb +0 -23
- data/sample/webrick/httpproxy.rb +0 -25
- data/sample/webrick/httpsd.rb +0 -33
- data/test/openssl/utils.rb +0 -313
- data/test/ruby/envutil.rb +0 -208
- data/test/webrick/test_cgi.rb +0 -134
- data/test/webrick/test_cookie.rb +0 -131
- data/test/webrick/test_filehandler.rb +0 -285
- data/test/webrick/test_httpauth.rb +0 -167
- data/test/webrick/test_httpproxy.rb +0 -282
- data/test/webrick/test_httprequest.rb +0 -411
- data/test/webrick/test_httpresponse.rb +0 -49
- data/test/webrick/test_httpserver.rb +0 -305
- data/test/webrick/test_httputils.rb +0 -96
- data/test/webrick/test_httpversion.rb +0 -40
- data/test/webrick/test_server.rb +0 -67
- data/test/webrick/test_utils.rb +0 -64
- data/test/webrick/utils.rb +0 -58
- data/test/webrick/webrick.cgi +0 -36
- data/test/webrick/webrick_long_filename.cgi +0 -36
@@ -1,40 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
require "webrick/httpversion"
|
3
|
-
|
4
|
-
class TestWEBrickHTTPVersion < Test::Unit::TestCase
|
5
|
-
def setup
|
6
|
-
@v09 = WEBrick::HTTPVersion.new("0.9")
|
7
|
-
@v10 = WEBrick::HTTPVersion.new("1.0")
|
8
|
-
@v11 = WEBrick::HTTPVersion.new("1.001")
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_to_s()
|
12
|
-
assert_equal("0.9", @v09.to_s)
|
13
|
-
assert_equal("1.0", @v10.to_s)
|
14
|
-
assert_equal("1.1", @v11.to_s)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_major()
|
18
|
-
assert_equal(0, @v09.major)
|
19
|
-
assert_equal(1, @v10.major)
|
20
|
-
assert_equal(1, @v11.major)
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_minor()
|
24
|
-
assert_equal(9, @v09.minor)
|
25
|
-
assert_equal(0, @v10.minor)
|
26
|
-
assert_equal(1, @v11.minor)
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_compar()
|
30
|
-
assert_equal(0, @v09 <=> "0.9")
|
31
|
-
assert_equal(0, @v09 <=> "0.09")
|
32
|
-
|
33
|
-
assert_equal(-1, @v09 <=> @v10)
|
34
|
-
assert_equal(-1, @v09 <=> "1.00")
|
35
|
-
|
36
|
-
assert_equal(1, @v11 <=> @v09)
|
37
|
-
assert_equal(1, @v11 <=> "1.0")
|
38
|
-
assert_equal(1, @v11 <=> "0.9")
|
39
|
-
end
|
40
|
-
end
|
data/test/webrick/test_server.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
require "tempfile"
|
3
|
-
require "webrick"
|
4
|
-
require_relative "utils"
|
5
|
-
|
6
|
-
class TestWEBrickServer < Test::Unit::TestCase
|
7
|
-
class Echo < WEBrick::GenericServer
|
8
|
-
def run(sock)
|
9
|
-
while line = sock.gets
|
10
|
-
sock << line
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_server
|
16
|
-
TestWEBrick.start_server(Echo){|server, addr, port, log|
|
17
|
-
TCPSocket.open(addr, port){|sock|
|
18
|
-
sock.puts("foo"); assert_equal("foo\n", sock.gets, log.call)
|
19
|
-
sock.puts("bar"); assert_equal("bar\n", sock.gets, log.call)
|
20
|
-
sock.puts("baz"); assert_equal("baz\n", sock.gets, log.call)
|
21
|
-
sock.puts("qux"); assert_equal("qux\n", sock.gets, log.call)
|
22
|
-
}
|
23
|
-
}
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_callbacks
|
27
|
-
accepted = started = stopped = 0
|
28
|
-
config = {
|
29
|
-
:AcceptCallback => Proc.new{ accepted += 1 },
|
30
|
-
:StartCallback => Proc.new{ started += 1 },
|
31
|
-
:StopCallback => Proc.new{ stopped += 1 },
|
32
|
-
}
|
33
|
-
TestWEBrick.start_server(Echo, config){|server, addr, port, log|
|
34
|
-
true while server.status != :Running
|
35
|
-
assert_equal(started, 1, log.call)
|
36
|
-
assert_equal(stopped, 0, log.call)
|
37
|
-
assert_equal(accepted, 0, log.call)
|
38
|
-
TCPSocket.open(addr, port){|sock| (sock << "foo\n").gets }
|
39
|
-
TCPSocket.open(addr, port){|sock| (sock << "foo\n").gets }
|
40
|
-
TCPSocket.open(addr, port){|sock| (sock << "foo\n").gets }
|
41
|
-
assert_equal(accepted, 3, log.call)
|
42
|
-
}
|
43
|
-
assert_equal(started, 1)
|
44
|
-
assert_equal(stopped, 1)
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_daemon
|
48
|
-
begin
|
49
|
-
r, w = IO.pipe
|
50
|
-
pid1 = Process.fork{
|
51
|
-
r.close
|
52
|
-
WEBrick::Daemon.start
|
53
|
-
w.puts(Process.pid)
|
54
|
-
sleep 10
|
55
|
-
}
|
56
|
-
pid2 = r.gets.to_i
|
57
|
-
assert(Process.kill(:KILL, pid2))
|
58
|
-
assert_not_equal(pid1, pid2)
|
59
|
-
rescue NotImplementedError
|
60
|
-
# snip this test
|
61
|
-
ensure
|
62
|
-
Process.wait(pid1) if pid1
|
63
|
-
r.close
|
64
|
-
w.close
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
data/test/webrick/test_utils.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
require "test/unit"
|
2
|
-
require "webrick/utils"
|
3
|
-
|
4
|
-
class TestWEBrickUtils < Test::Unit::TestCase
|
5
|
-
def assert_expired(flag, m)
|
6
|
-
if m == WEBrick::Utils
|
7
|
-
handler = WEBrick::Utils::TimeoutHandler.instance
|
8
|
-
assert_equal(flag, handler.instance_eval{ @timeout_info.empty? })
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def do_test_timeout(m)
|
13
|
-
ex = Class.new(StandardError)
|
14
|
-
|
15
|
-
assert_equal(:foo, m.timeout(10){ :foo })
|
16
|
-
assert_expired(true, m)
|
17
|
-
|
18
|
-
i = 0
|
19
|
-
assert_raise(Timeout::Error){
|
20
|
-
m.timeout(2){
|
21
|
-
assert_raise(Timeout::Error){ m.timeout(1){ i += 1; sleep } }
|
22
|
-
assert_expired(false, m)
|
23
|
-
i += 1
|
24
|
-
sleep
|
25
|
-
}
|
26
|
-
}
|
27
|
-
assert_equal(2, i)
|
28
|
-
assert_expired(true, m)
|
29
|
-
|
30
|
-
assert_raise(Timeout::Error){ m.timeout(0.1){ sleep } }
|
31
|
-
assert_expired(true, m)
|
32
|
-
|
33
|
-
assert_raise(ex){ m.timeout(0.1, ex){ sleep } }
|
34
|
-
assert_expired(true, m)
|
35
|
-
|
36
|
-
i = 0
|
37
|
-
assert_raise(ex){
|
38
|
-
m.timeout(10){
|
39
|
-
m.timeout(1, ex){ i += 1; sleep }
|
40
|
-
}
|
41
|
-
sleep
|
42
|
-
}
|
43
|
-
assert_equal(1, i)
|
44
|
-
assert_expired(true, m)
|
45
|
-
|
46
|
-
i = 0
|
47
|
-
assert_raise(Timeout::Error){
|
48
|
-
m.timeout(1){
|
49
|
-
m.timeout(10, ex){ i += 1; sleep }
|
50
|
-
}
|
51
|
-
sleep
|
52
|
-
}
|
53
|
-
assert_equal(1, i)
|
54
|
-
assert_expired(true, m)
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_webrick_timeout
|
58
|
-
do_test_timeout(WEBrick::Utils)
|
59
|
-
end
|
60
|
-
|
61
|
-
#def test_timeout
|
62
|
-
# do_test_timeout(Timeout)
|
63
|
-
#end
|
64
|
-
end
|
data/test/webrick/utils.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
require_relative '../ruby/envutil'
|
2
|
-
require "webrick"
|
3
|
-
begin
|
4
|
-
require "webrick/https"
|
5
|
-
rescue LoadError
|
6
|
-
end
|
7
|
-
require "webrick/httpproxy"
|
8
|
-
|
9
|
-
module TestWEBrick
|
10
|
-
NullWriter = Object.new
|
11
|
-
def NullWriter.<<(msg)
|
12
|
-
puts msg if $DEBUG
|
13
|
-
return self
|
14
|
-
end
|
15
|
-
|
16
|
-
RubyBin = "\"#{EnvUtil.rubybin}\""
|
17
|
-
RubyBin << " --disable-gems"
|
18
|
-
RubyBin << " \"-I#{File.expand_path("../..", File.dirname(__FILE__))}/lib\""
|
19
|
-
RubyBin << " \"-I#{File.dirname(EnvUtil.rubybin)}/.ext/common\""
|
20
|
-
RubyBin << " \"-I#{File.dirname(EnvUtil.rubybin)}/.ext/#{RUBY_PLATFORM}\""
|
21
|
-
|
22
|
-
module_function
|
23
|
-
|
24
|
-
def start_server(klass, config={}, &block)
|
25
|
-
log_string = ""
|
26
|
-
logger = Object.new
|
27
|
-
logger.instance_eval do
|
28
|
-
define_singleton_method(:<<) {|msg| log_string << msg }
|
29
|
-
end
|
30
|
-
log = proc { "webrick log start:\n" + log_string.gsub(/^/, " ").chomp + "\nwebrick log end" }
|
31
|
-
server = klass.new({
|
32
|
-
:BindAddress => "127.0.0.1", :Port => 0,
|
33
|
-
:ShutdownSocketWithoutClose =>true,
|
34
|
-
:ServerType => Thread,
|
35
|
-
:Logger => WEBrick::Log.new(logger),
|
36
|
-
:AccessLog => [[logger, ""]]
|
37
|
-
}.update(config))
|
38
|
-
begin
|
39
|
-
server.start
|
40
|
-
addr = server.listeners[0].addr
|
41
|
-
block.yield([server, addr[3], addr[1], log])
|
42
|
-
ensure
|
43
|
-
server.shutdown
|
44
|
-
until server.status == :Stop
|
45
|
-
sleep 0.1
|
46
|
-
end
|
47
|
-
end
|
48
|
-
log_string
|
49
|
-
end
|
50
|
-
|
51
|
-
def start_httpserver(config={}, &block)
|
52
|
-
start_server(WEBrick::HTTPServer, config, &block)
|
53
|
-
end
|
54
|
-
|
55
|
-
def start_httpproxy(config={}, &block)
|
56
|
-
start_server(WEBrick::HTTPProxyServer, config, &block)
|
57
|
-
end
|
58
|
-
end
|
data/test/webrick/webrick.cgi
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
#!ruby -d
|
2
|
-
require "webrick/cgi"
|
3
|
-
|
4
|
-
class TestApp < WEBrick::CGI
|
5
|
-
def do_GET(req, res)
|
6
|
-
res["content-type"] = "text/plain"
|
7
|
-
if (p = req.path_info) && p.length > 0
|
8
|
-
res.body = p
|
9
|
-
elsif (q = req.query).size > 0
|
10
|
-
res.body = q.keys.sort.collect{|key|
|
11
|
-
q[key].list.sort.collect{|v|
|
12
|
-
"#{key}=#{v}"
|
13
|
-
}.join(", ")
|
14
|
-
}.join(", ")
|
15
|
-
elsif %r{/$} =~ req.request_uri.to_s
|
16
|
-
res.body = ""
|
17
|
-
res.body << req.request_uri.to_s << "\n"
|
18
|
-
res.body << req.script_name
|
19
|
-
elsif !req.cookies.empty?
|
20
|
-
res.body = req.cookies.inject(""){|result, cookie|
|
21
|
-
result << "%s=%s\n" % [cookie.name, cookie.value]
|
22
|
-
}
|
23
|
-
res.cookies << WEBrick::Cookie.new("Customer", "WILE_E_COYOTE")
|
24
|
-
res.cookies << WEBrick::Cookie.new("Shipping", "FedEx")
|
25
|
-
else
|
26
|
-
res.body = req.script_name
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def do_POST(req, res)
|
31
|
-
do_GET(req, res)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
cgi = TestApp.new
|
36
|
-
cgi.start
|
@@ -1,36 +0,0 @@
|
|
1
|
-
#!ruby -d
|
2
|
-
require "webrick/cgi"
|
3
|
-
|
4
|
-
class TestApp < WEBrick::CGI
|
5
|
-
def do_GET(req, res)
|
6
|
-
res["content-type"] = "text/plain"
|
7
|
-
if (p = req.path_info) && p.length > 0
|
8
|
-
res.body = p
|
9
|
-
elsif (q = req.query).size > 0
|
10
|
-
res.body = q.keys.sort.collect{|key|
|
11
|
-
q[key].list.sort.collect{|v|
|
12
|
-
"#{key}=#{v}"
|
13
|
-
}.join(", ")
|
14
|
-
}.join(", ")
|
15
|
-
elsif %r{/$} =~ req.request_uri.to_s
|
16
|
-
res.body = ""
|
17
|
-
res.body << req.request_uri.to_s << "\n"
|
18
|
-
res.body << req.script_name
|
19
|
-
elsif !req.cookies.empty?
|
20
|
-
res.body = req.cookies.inject(""){|result, cookie|
|
21
|
-
result << "%s=%s\n" % [cookie.name, cookie.value]
|
22
|
-
}
|
23
|
-
res.cookies << WEBrick::Cookie.new("Customer", "WILE_E_COYOTE")
|
24
|
-
res.cookies << WEBrick::Cookie.new("Shipping", "FedEx")
|
25
|
-
else
|
26
|
-
res.body = req.script_name
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def do_POST(req, res)
|
31
|
-
do_GET(req, res)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
cgi = TestApp.new
|
36
|
-
cgi.start
|