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.

Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/lib/webrick.rb +6 -6
  3. data/lib/webrick/accesslog.rb +9 -1
  4. data/lib/webrick/cgi.rb +58 -5
  5. data/lib/webrick/compat.rb +2 -1
  6. data/lib/webrick/config.rb +47 -10
  7. data/lib/webrick/cookie.rb +69 -7
  8. data/lib/webrick/htmlutils.rb +4 -2
  9. data/lib/webrick/httpauth.rb +6 -5
  10. data/lib/webrick/httpauth/authenticator.rb +13 -8
  11. data/lib/webrick/httpauth/basicauth.rb +16 -8
  12. data/lib/webrick/httpauth/digestauth.rb +35 -32
  13. data/lib/webrick/httpauth/htdigest.rb +12 -8
  14. data/lib/webrick/httpauth/htgroup.rb +10 -6
  15. data/lib/webrick/httpauth/htpasswd.rb +46 -9
  16. data/lib/webrick/httpauth/userdb.rb +1 -0
  17. data/lib/webrick/httpproxy.rb +93 -48
  18. data/lib/webrick/httprequest.rb +192 -27
  19. data/lib/webrick/httpresponse.rb +182 -62
  20. data/lib/webrick/https.rb +90 -2
  21. data/lib/webrick/httpserver.rb +45 -15
  22. data/lib/webrick/httpservlet.rb +6 -5
  23. data/lib/webrick/httpservlet/abstract.rb +5 -6
  24. data/lib/webrick/httpservlet/cgi_runner.rb +3 -2
  25. data/lib/webrick/httpservlet/cgihandler.rb +22 -10
  26. data/lib/webrick/httpservlet/erbhandler.rb +4 -3
  27. data/lib/webrick/httpservlet/filehandler.rb +136 -65
  28. data/lib/webrick/httpservlet/prochandler.rb +15 -1
  29. data/lib/webrick/httpstatus.rb +24 -14
  30. data/lib/webrick/httputils.rb +132 -13
  31. data/lib/webrick/httpversion.rb +28 -1
  32. data/lib/webrick/log.rb +25 -5
  33. data/lib/webrick/server.rb +234 -74
  34. data/lib/webrick/ssl.rb +100 -12
  35. data/lib/webrick/utils.rb +98 -69
  36. data/lib/webrick/version.rb +6 -1
  37. metadata +66 -72
  38. data/README.txt +0 -21
  39. data/sample/webrick/demo-app.rb +0 -66
  40. data/sample/webrick/demo-multipart.cgi +0 -12
  41. data/sample/webrick/demo-servlet.rb +0 -6
  42. data/sample/webrick/demo-urlencoded.cgi +0 -12
  43. data/sample/webrick/hello.cgi +0 -11
  44. data/sample/webrick/hello.rb +0 -8
  45. data/sample/webrick/httpd.rb +0 -23
  46. data/sample/webrick/httpproxy.rb +0 -25
  47. data/sample/webrick/httpsd.rb +0 -33
  48. data/test/openssl/utils.rb +0 -313
  49. data/test/ruby/envutil.rb +0 -208
  50. data/test/webrick/test_cgi.rb +0 -134
  51. data/test/webrick/test_cookie.rb +0 -131
  52. data/test/webrick/test_filehandler.rb +0 -285
  53. data/test/webrick/test_httpauth.rb +0 -167
  54. data/test/webrick/test_httpproxy.rb +0 -282
  55. data/test/webrick/test_httprequest.rb +0 -411
  56. data/test/webrick/test_httpresponse.rb +0 -49
  57. data/test/webrick/test_httpserver.rb +0 -305
  58. data/test/webrick/test_httputils.rb +0 -96
  59. data/test/webrick/test_httpversion.rb +0 -40
  60. data/test/webrick/test_server.rb +0 -67
  61. data/test/webrick/test_utils.rb +0 -64
  62. data/test/webrick/utils.rb +0 -58
  63. data/test/webrick/webrick.cgi +0 -36
  64. data/test/webrick/webrick_long_filename.cgi +0 -36
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f5e6d9bdc4f99de4e0488649df6d801d9c4ccef823d2d74916548b9eca6652a8
4
+ data.tar.gz: 7cbac41b577d94a74fd451e4181489ffccaa9ce2bf54fcbfde2a81cf28c4728f
5
+ SHA512:
6
+ metadata.gz: aafcd2d775674d2d987492130119eb6b3f497443b1a0c702b1717ed94514b9ea7ce166c2937035ce465ae8e582312896e8b317973a826d4cd5de79809a626710
7
+ data.tar.gz: 7a5657cb4868485516c660a0d65aa937522d5f8db923cd72e029b227f35b324967b4347265d1b80dd273f7cf98670e3328c3ebb0e08e02c1b6e0f638b175cf26
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: false
1
2
  ##
2
3
  # = WEB server toolkit.
3
4
  #
@@ -6,9 +7,9 @@
6
7
  # logging of both server operations and HTTP access. WEBrick supports both
7
8
  # basic and digest authentication in addition to algorithms not in RFC 2617.
8
9
  #
9
- # A WEBrick servers can be composed of multiple WEBrick servers or servlets to
10
+ # A WEBrick server can be composed of multiple WEBrick servers or servlets to
10
11
  # provide differing behavior on a per-host or per-path basis. WEBrick
11
- # includes servlets for handling CGI scripts, ERb pages, ruby blocks and
12
+ # includes servlets for handling CGI scripts, ERB pages, Ruby blocks and
12
13
  # directory listings.
13
14
  #
14
15
  # WEBrick also includes tools for daemonizing a process and starting a process
@@ -42,7 +43,7 @@
42
43
  # res.body = 'Hello, world!'
43
44
  # end
44
45
  #
45
- # Remember that <tt>server.mount_proc</tt> must <tt>server.start</tt>.
46
+ # Remember that +server.mount_proc+ must precede +server.start+.
46
47
  #
47
48
  # == Servlets
48
49
  #
@@ -129,9 +130,8 @@
129
130
  #
130
131
  # trap 'INT' do proxy.shutdown end
131
132
  #
132
- # Proxies may modifier the content of the response through the
133
- # +:ProxyContentHandler+ callback which will be invoked with the request and
134
- # respone after the remote content has been fetched.
133
+ # See WEBrick::HTTPProxy for further details including modifying proxied
134
+ # responses.
135
135
  #
136
136
  # == Basic and Digest authentication
137
137
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: false
1
2
  #--
2
3
  # accesslog.rb -- Access log handling utilities
3
4
  #
@@ -85,7 +86,7 @@ module WEBrick
85
86
  # %q:: Request query string
86
87
  # %r:: First line of the request
87
88
  # %s:: Request status
88
- # %t:: Time the request was recieved
89
+ # %t:: Time the request was received
89
90
  # %T:: Time taken to process the request
90
91
  # %u:: Remote user from auth
91
92
  # %U:: Unparsed URI
@@ -115,6 +116,10 @@ module WEBrick
115
116
  params
116
117
  end
117
118
 
119
+ ##
120
+ # Formats +params+ according to +format_string+ which is described in
121
+ # setup_params.
122
+
118
123
  def format(format_string, params)
119
124
  format_string.gsub(/\%(?:\{(.*?)\})?>?([a-zA-Z%])/){
120
125
  param, spec = $1, $2
@@ -140,6 +145,9 @@ module WEBrick
140
145
  }
141
146
  end
142
147
 
148
+ ##
149
+ # Escapes control characters in +data+
150
+
143
151
  def escape(data)
144
152
  if data.tainted?
145
153
  data.gsub(/[[:cntrl:]\\]+/) {$&.dump[1...-1]}.untaint
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: false
1
2
  #
2
3
  # cgi.rb -- Yet another CGI library
3
4
  #
@@ -7,16 +8,50 @@
7
8
  #
8
9
  # $Id$
9
10
 
10
- require "webrick/httprequest"
11
- require "webrick/httpresponse"
12
- require "webrick/config"
11
+ require_relative "httprequest"
12
+ require_relative "httpresponse"
13
+ require_relative "config"
13
14
  require "stringio"
14
15
 
15
16
  module WEBrick
17
+
18
+ # A CGI library using WEBrick requests and responses.
19
+ #
20
+ # Example:
21
+ #
22
+ # class MyCGI < WEBrick::CGI
23
+ # def do_GET req, res
24
+ # res.body = 'it worked!'
25
+ # res.status = 200
26
+ # end
27
+ # end
28
+ #
29
+ # MyCGI.new.start
30
+
16
31
  class CGI
32
+
33
+ # The CGI error exception class
34
+
17
35
  CGIError = Class.new(StandardError)
18
36
 
19
- attr_reader :config, :logger
37
+ ##
38
+ # The CGI configuration. This is based on WEBrick::Config::HTTP
39
+
40
+ attr_reader :config
41
+
42
+ ##
43
+ # The CGI logger
44
+
45
+ attr_reader :logger
46
+
47
+ ##
48
+ # Creates a new CGI interface.
49
+ #
50
+ # The first argument in +args+ is a configuration hash which would update
51
+ # WEBrick::Config::HTTP.
52
+ #
53
+ # Any remaining arguments are stored in the <code>@options</code> instance
54
+ # variable for use by a subclass.
20
55
 
21
56
  def initialize(*args)
22
57
  if defined?(MOD_RUBY)
@@ -41,10 +76,17 @@ module WEBrick
41
76
  @options = args
42
77
  end
43
78
 
79
+ ##
80
+ # Reads +key+ from the configuration
81
+
44
82
  def [](key)
45
83
  @config[key]
46
84
  end
47
85
 
86
+ ##
87
+ # Starts the CGI process with the given environment +env+ and standard
88
+ # input and output +stdin+ and +stdout+.
89
+
48
90
  def start(env=ENV, stdin=$stdin, stdout=$stdout)
49
91
  sock = WEBrick::CGI::Socket.new(@config, env, stdin, stdout)
50
92
  req = HTTPRequest.new(@config)
@@ -108,6 +150,10 @@ module WEBrick
108
150
  end
109
151
  end
110
152
 
153
+ ##
154
+ # Services the request +req+ which will fill in the response +res+. See
155
+ # WEBrick::HTTPServlet::AbstractServlet#service for details.
156
+
111
157
  def service(req, res)
112
158
  method_name = "do_" + req.request_method.gsub(/-/, "_")
113
159
  if respond_to?(method_name)
@@ -118,7 +164,10 @@ module WEBrick
118
164
  end
119
165
  end
120
166
 
121
- class Socket
167
+ ##
168
+ # Provides HTTP socket emulation from the CGI environment
169
+
170
+ class Socket # :nodoc:
122
171
  include Enumerable
123
172
 
124
173
  private
@@ -216,6 +265,10 @@ module WEBrick
216
265
  @out_port << data
217
266
  end
218
267
 
268
+ def write(data)
269
+ @out_port.write(data)
270
+ end
271
+
219
272
  def cert
220
273
  return nil unless defined?(OpenSSL)
221
274
  if pem = @env["SSL_SERVER_CERT"]
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: false
1
2
  #
2
3
  # compat.rb -- cross platform compatibility
3
4
  #
@@ -9,7 +10,7 @@
9
10
  # $IPR: compat.rb,v 1.6 2002/10/01 17:16:32 gotoyuzo Exp $
10
11
 
11
12
  ##
12
- # System call error module used by webrick for cross platform compatability.
13
+ # System call error module used by webrick for cross platform compatibility.
13
14
  #
14
15
  # EPROTO:: protocol error
15
16
  # ECONNRESET:: remote host reset the connection request
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: false
1
2
  #
2
3
  # config.rb -- Default configurations.
3
4
  #
@@ -8,19 +9,25 @@
8
9
  #
9
10
  # $IPR: config.rb,v 1.52 2003/07/22 19:20:42 gotoyuzo Exp $
10
11
 
11
- require 'webrick/version'
12
- require 'webrick/httpversion'
13
- require 'webrick/httputils'
14
- require 'webrick/utils'
15
- require 'webrick/log'
12
+ require_relative 'version'
13
+ require_relative 'httpversion'
14
+ require_relative 'httputils'
15
+ require_relative 'utils'
16
+ require_relative 'log'
16
17
 
17
18
  module WEBrick
18
19
  module Config
19
- LIBDIR = File::dirname(__FILE__)
20
+ LIBDIR = File::dirname(__FILE__) # :nodoc:
20
21
 
21
22
  # for GenericServer
22
- General = {
23
- :ServerName => Utils::getservername,
23
+ General = Hash.new { |hash, key|
24
+ case key
25
+ when :ServerName
26
+ hash[key] = Utils.getservername
27
+ else
28
+ nil
29
+ end
30
+ }.update(
24
31
  :BindAddress => nil, # "0.0.0.0" or "::" or nil
25
32
  :Port => nil, # users MUST specify this!!
26
33
  :MaxClients => 100, # maximum number of the concurrent connections
@@ -33,9 +40,9 @@ module WEBrick
33
40
  :StartCallback => nil,
34
41
  :StopCallback => nil,
35
42
  :AcceptCallback => nil,
36
- :DoNotReverseLookup => nil,
43
+ :DoNotReverseLookup => true,
37
44
  :ShutdownSocketWithoutClose => false,
38
- }
45
+ )
39
46
 
40
47
  # for HTTPServer, HTTPRequest, HTTPResponse ...
41
48
  HTTP = General.dup.update(
@@ -67,6 +74,30 @@ module WEBrick
67
74
  :Escape8bitURI => false
68
75
  )
69
76
 
77
+ ##
78
+ # Default configuration for WEBrick::HTTPServlet::FileHandler
79
+ #
80
+ # :AcceptableLanguages::
81
+ # Array of languages allowed for accept-language. There is no default
82
+ # :DirectoryCallback::
83
+ # Allows preprocessing of directory requests. There is no default
84
+ # callback.
85
+ # :FancyIndexing::
86
+ # If true, show an index for directories. The default is true.
87
+ # :FileCallback::
88
+ # Allows preprocessing of file requests. There is no default callback.
89
+ # :HandlerCallback::
90
+ # Allows preprocessing of requests. There is no default callback.
91
+ # :HandlerTable::
92
+ # Maps file suffixes to file handlers. DefaultFileHandler is used by
93
+ # default but any servlet can be used.
94
+ # :NondisclosureName::
95
+ # Do not show files matching this array of globs. .ht* and *~ are
96
+ # excluded by default.
97
+ # :UserDir::
98
+ # Directory inside ~user to serve content from for /~user requests.
99
+ # Only works if mounted on /. Disabled by default.
100
+
70
101
  FileHandler = {
71
102
  :NondisclosureName => [".ht*", "*~"],
72
103
  :FancyIndexing => false,
@@ -78,6 +109,12 @@ module WEBrick
78
109
  :AcceptableLanguages => [] # ["en", "ja", ... ]
79
110
  }
80
111
 
112
+ ##
113
+ # Default configuration for WEBrick::HTTPAuth::BasicAuth
114
+ #
115
+ # :AutoReloadUserDB:: Reload the user database provided by :UserDB
116
+ # automatically?
117
+
81
118
  BasicAuth = {
82
119
  :AutoReloadUserDB => true,
83
120
  }
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: false
1
2
  #
2
3
  # cookie.rb -- Cookie class
3
4
  #
@@ -9,17 +10,59 @@
9
10
  # $IPR: cookie.rb,v 1.16 2002/09/21 12:23:35 gotoyuzo Exp $
10
11
 
11
12
  require 'time'
12
- require 'webrick/httputils'
13
+ require_relative 'httputils'
13
14
 
14
15
  module WEBrick
16
+
17
+ ##
18
+ # Processes HTTP cookies
19
+
15
20
  class Cookie
16
21
 
22
+ ##
23
+ # The cookie name
24
+
17
25
  attr_reader :name
18
- attr_accessor :value, :version
19
- attr_accessor :domain, :path, :secure
20
- attr_accessor :comment, :max_age
26
+
27
+ ##
28
+ # The cookie value
29
+
30
+ attr_accessor :value
31
+
32
+ ##
33
+ # The cookie version
34
+
35
+ attr_accessor :version
36
+
37
+ ##
38
+ # The cookie domain
39
+ attr_accessor :domain
40
+
41
+ ##
42
+ # The cookie path
43
+
44
+ attr_accessor :path
45
+
46
+ ##
47
+ # Is this a secure cookie?
48
+
49
+ attr_accessor :secure
50
+
51
+ ##
52
+ # The cookie comment
53
+
54
+ attr_accessor :comment
55
+
56
+ ##
57
+ # The maximum age of the cookie
58
+
59
+ attr_accessor :max_age
60
+
21
61
  #attr_accessor :comment_url, :discard, :port
22
62
 
63
+ ##
64
+ # Creates a new cookie with the given +name+ and +value+
65
+
23
66
  def initialize(name, value)
24
67
  @name = name
25
68
  @value = value
@@ -29,14 +72,25 @@ module WEBrick
29
72
  @expires = @comment_url = @discard = @port = nil
30
73
  end
31
74
 
75
+ ##
76
+ # Sets the cookie expiration to the time +t+. The expiration time may be
77
+ # a false value to disable expiration or a Time or HTTP format time string
78
+ # to set the expiration date.
79
+
32
80
  def expires=(t)
33
81
  @expires = t && (t.is_a?(Time) ? t.httpdate : t.to_s)
34
82
  end
35
83
 
84
+ ##
85
+ # Retrieves the expiration time as a Time
86
+
36
87
  def expires
37
88
  @expires && Time.parse(@expires)
38
89
  end
39
90
 
91
+ ##
92
+ # The cookie string suitable for use in an HTTP header
93
+
40
94
  def to_s
41
95
  ret = ""
42
96
  ret << @name << "=" << @value
@@ -50,14 +104,16 @@ module WEBrick
50
104
  ret
51
105
  end
52
106
 
53
- # Cookie::parse()
54
- # It parses Cookie field sent from the user agent.
107
+ ##
108
+ # Parses a Cookie field sent from the user-agent. Returns an array of
109
+ # cookies.
110
+
55
111
  def self.parse(str)
56
112
  if str
57
113
  ret = []
58
114
  cookie = nil
59
115
  ver = 0
60
- str.split(/[;,]\s+/).each{|x|
116
+ str.split(/;\s+/).each{|x|
61
117
  key, val = x.split(/=/,2)
62
118
  val = val ? HTTPUtils::dequote(val) : ""
63
119
  case key
@@ -76,6 +132,9 @@ module WEBrick
76
132
  end
77
133
  end
78
134
 
135
+ ##
136
+ # Parses the cookie in +str+
137
+
79
138
  def self.parse_set_cookie(str)
80
139
  cookie_elem = str.split(/;/)
81
140
  first_elem = cookie_elem.shift
@@ -101,6 +160,9 @@ module WEBrick
101
160
  return cookie
102
161
  end
103
162
 
163
+ ##
164
+ # Parses the cookies in +str+
165
+
104
166
  def self.parse_set_cookies(str)
105
167
  return str.split(/,(?=[^;,]*=)|,$/).collect{|c|
106
168
  parse_set_cookie(c)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: false
1
2
  #--
2
3
  # htmlutils.rb -- HTMLUtils Module
3
4
  #
@@ -15,12 +16,13 @@ module WEBrick
15
16
  # Escapes &, ", > and < in +string+
16
17
 
17
18
  def escape(string)
18
- str = string ? string.dup : ""
19
+ return "" unless string
20
+ str = string.b
19
21
  str.gsub!(/&/n, '&amp;')
20
22
  str.gsub!(/\"/n, '&quot;')
21
23
  str.gsub!(/>/n, '&gt;')
22
24
  str.gsub!(/</n, '&lt;')
23
- str
25
+ str.force_encoding(string.encoding)
24
26
  end
25
27
  module_function :escape
26
28