webrick 1.3.1

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.

Files changed (63) hide show
  1. data/README.txt +21 -0
  2. data/lib/webrick.rb +227 -0
  3. data/lib/webrick/accesslog.rb +151 -0
  4. data/lib/webrick/cgi.rb +260 -0
  5. data/lib/webrick/compat.rb +35 -0
  6. data/lib/webrick/config.rb +121 -0
  7. data/lib/webrick/cookie.rb +110 -0
  8. data/lib/webrick/htmlutils.rb +28 -0
  9. data/lib/webrick/httpauth.rb +95 -0
  10. data/lib/webrick/httpauth/authenticator.rb +112 -0
  11. data/lib/webrick/httpauth/basicauth.rb +108 -0
  12. data/lib/webrick/httpauth/digestauth.rb +392 -0
  13. data/lib/webrick/httpauth/htdigest.rb +128 -0
  14. data/lib/webrick/httpauth/htgroup.rb +93 -0
  15. data/lib/webrick/httpauth/htpasswd.rb +121 -0
  16. data/lib/webrick/httpauth/userdb.rb +52 -0
  17. data/lib/webrick/httpproxy.rb +305 -0
  18. data/lib/webrick/httprequest.rb +461 -0
  19. data/lib/webrick/httpresponse.rb +399 -0
  20. data/lib/webrick/https.rb +64 -0
  21. data/lib/webrick/httpserver.rb +264 -0
  22. data/lib/webrick/httpservlet.rb +22 -0
  23. data/lib/webrick/httpservlet/abstract.rb +153 -0
  24. data/lib/webrick/httpservlet/cgi_runner.rb +46 -0
  25. data/lib/webrick/httpservlet/cgihandler.rb +108 -0
  26. data/lib/webrick/httpservlet/erbhandler.rb +87 -0
  27. data/lib/webrick/httpservlet/filehandler.rb +470 -0
  28. data/lib/webrick/httpservlet/prochandler.rb +33 -0
  29. data/lib/webrick/httpstatus.rb +184 -0
  30. data/lib/webrick/httputils.rb +394 -0
  31. data/lib/webrick/httpversion.rb +49 -0
  32. data/lib/webrick/log.rb +136 -0
  33. data/lib/webrick/server.rb +218 -0
  34. data/lib/webrick/ssl.rb +127 -0
  35. data/lib/webrick/utils.rb +241 -0
  36. data/lib/webrick/version.rb +13 -0
  37. data/sample/webrick/demo-app.rb +66 -0
  38. data/sample/webrick/demo-multipart.cgi +12 -0
  39. data/sample/webrick/demo-servlet.rb +6 -0
  40. data/sample/webrick/demo-urlencoded.cgi +12 -0
  41. data/sample/webrick/hello.cgi +11 -0
  42. data/sample/webrick/hello.rb +8 -0
  43. data/sample/webrick/httpd.rb +23 -0
  44. data/sample/webrick/httpproxy.rb +25 -0
  45. data/sample/webrick/httpsd.rb +33 -0
  46. data/test/openssl/utils.rb +313 -0
  47. data/test/ruby/envutil.rb +208 -0
  48. data/test/webrick/test_cgi.rb +134 -0
  49. data/test/webrick/test_cookie.rb +131 -0
  50. data/test/webrick/test_filehandler.rb +285 -0
  51. data/test/webrick/test_httpauth.rb +167 -0
  52. data/test/webrick/test_httpproxy.rb +282 -0
  53. data/test/webrick/test_httprequest.rb +411 -0
  54. data/test/webrick/test_httpresponse.rb +49 -0
  55. data/test/webrick/test_httpserver.rb +305 -0
  56. data/test/webrick/test_httputils.rb +96 -0
  57. data/test/webrick/test_httpversion.rb +40 -0
  58. data/test/webrick/test_server.rb +67 -0
  59. data/test/webrick/test_utils.rb +64 -0
  60. data/test/webrick/utils.rb +58 -0
  61. data/test/webrick/webrick.cgi +36 -0
  62. data/test/webrick/webrick_long_filename.cgi +36 -0
  63. metadata +106 -0
@@ -0,0 +1,40 @@
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
@@ -0,0 +1,67 @@
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
@@ -0,0 +1,64 @@
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
@@ -0,0 +1,58 @@
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
@@ -0,0 +1,36 @@
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
@@ -0,0 +1,36 @@
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
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webrick
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - IPR -- Internet Programming with Ruby -- writers
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-28 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email: nahi@ruby-lang.org
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/webrick/https.rb
21
+ - lib/webrick/httpservlet/cgi_runner.rb
22
+ - lib/webrick/httpservlet/erbhandler.rb
23
+ - lib/webrick/httpservlet/filehandler.rb
24
+ - lib/webrick/httpservlet/prochandler.rb
25
+ - lib/webrick/httpservlet/abstract.rb
26
+ - lib/webrick/httpservlet/cgihandler.rb
27
+ - lib/webrick/compat.rb
28
+ - lib/webrick/httpresponse.rb
29
+ - lib/webrick/accesslog.rb
30
+ - lib/webrick/httpversion.rb
31
+ - lib/webrick/utils.rb
32
+ - lib/webrick/version.rb
33
+ - lib/webrick/httprequest.rb
34
+ - lib/webrick/httpauth.rb
35
+ - lib/webrick/server.rb
36
+ - lib/webrick/httpproxy.rb
37
+ - lib/webrick/ssl.rb
38
+ - lib/webrick/cgi.rb
39
+ - lib/webrick/httpstatus.rb
40
+ - lib/webrick/htmlutils.rb
41
+ - lib/webrick/httpserver.rb
42
+ - lib/webrick/cookie.rb
43
+ - lib/webrick/httputils.rb
44
+ - lib/webrick/httpauth/basicauth.rb
45
+ - lib/webrick/httpauth/digestauth.rb
46
+ - lib/webrick/httpauth/authenticator.rb
47
+ - lib/webrick/httpauth/htdigest.rb
48
+ - lib/webrick/httpauth/htgroup.rb
49
+ - lib/webrick/httpauth/htpasswd.rb
50
+ - lib/webrick/httpauth/userdb.rb
51
+ - lib/webrick/config.rb
52
+ - lib/webrick/httpservlet.rb
53
+ - lib/webrick/log.rb
54
+ - lib/webrick.rb
55
+ - sample/webrick/demo-urlencoded.cgi
56
+ - sample/webrick/demo-multipart.cgi
57
+ - sample/webrick/hello.rb
58
+ - sample/webrick/hello.cgi
59
+ - sample/webrick/httpproxy.rb
60
+ - sample/webrick/httpsd.rb
61
+ - sample/webrick/httpd.rb
62
+ - sample/webrick/demo-app.rb
63
+ - sample/webrick/demo-servlet.rb
64
+ - test/webrick/webrick_long_filename.cgi
65
+ - test/webrick/utils.rb
66
+ - test/webrick/test_httpproxy.rb
67
+ - test/webrick/test_cookie.rb
68
+ - test/webrick/test_server.rb
69
+ - test/webrick/test_httpresponse.rb
70
+ - test/webrick/test_utils.rb
71
+ - test/webrick/test_httpserver.rb
72
+ - test/webrick/test_httprequest.rb
73
+ - test/webrick/test_httpversion.rb
74
+ - test/webrick/webrick.cgi
75
+ - test/webrick/test_httpauth.rb
76
+ - test/webrick/test_cgi.rb
77
+ - test/webrick/test_httputils.rb
78
+ - test/webrick/test_filehandler.rb
79
+ - test/ruby/envutil.rb
80
+ - test/openssl/utils.rb
81
+ - README.txt
82
+ homepage: http://github.com/nahi/webrick
83
+ licenses: []
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubyforge_project:
102
+ rubygems_version: 1.8.11
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: WEBrick is an HTTP server toolkit that can be configured as an HTTPS server,
106
+ test_files: []