webrick 1.3.1 → 1.4.0.beta1

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 +51 -2
  5. data/lib/webrick/compat.rb +2 -1
  6. data/lib/webrick/config.rb +42 -5
  7. data/lib/webrick/cookie.rb +68 -6
  8. data/lib/webrick/htmlutils.rb +4 -2
  9. data/lib/webrick/httpauth.rb +1 -0
  10. data/lib/webrick/httpauth/authenticator.rb +13 -8
  11. data/lib/webrick/httpauth/basicauth.rb +3 -3
  12. data/lib/webrick/httpauth/digestauth.rb +25 -9
  13. data/lib/webrick/httpauth/htdigest.rb +8 -4
  14. data/lib/webrick/httpauth/htgroup.rb +1 -0
  15. data/lib/webrick/httpauth/htpasswd.rb +7 -3
  16. data/lib/webrick/httpauth/userdb.rb +1 -0
  17. data/lib/webrick/httpproxy.rb +47 -14
  18. data/lib/webrick/httprequest.rb +142 -16
  19. data/lib/webrick/httpresponse.rb +96 -24
  20. data/lib/webrick/https.rb +24 -1
  21. data/lib/webrick/httpserver.rb +20 -4
  22. data/lib/webrick/httpservlet.rb +1 -0
  23. data/lib/webrick/httpservlet/abstract.rb +2 -1
  24. data/lib/webrick/httpservlet/cgi_runner.rb +1 -0
  25. data/lib/webrick/httpservlet/cgihandler.rb +19 -5
  26. data/lib/webrick/httpservlet/erbhandler.rb +2 -1
  27. data/lib/webrick/httpservlet/filehandler.rb +87 -34
  28. data/lib/webrick/httpservlet/prochandler.rb +14 -0
  29. data/lib/webrick/httpstatus.rb +24 -10
  30. data/lib/webrick/httputils.rb +129 -13
  31. data/lib/webrick/httpversion.rb +28 -1
  32. data/lib/webrick/log.rb +22 -2
  33. data/lib/webrick/server.rb +203 -60
  34. data/lib/webrick/ssl.rb +80 -5
  35. data/lib/webrick/utils.rb +97 -67
  36. data/lib/webrick/version.rb +6 -1
  37. metadata +59 -69
  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
+ SHA1:
3
+ metadata.gz: 24fd7f86aee41c3b6f2d1017f780739cd68103a1
4
+ data.tar.gz: a6ce1434723786cd182d31042dbb658dbe8f1cef
5
+ SHA512:
6
+ metadata.gz: 1f4874e7a0e49a67c93d35237b7eeaa12778d1a5bdf3201809101b426336ddb2e6663ec9f747c42482937c515085bcb31975fce182e3dfc78bd15b7728f3c55f
7
+ data.tar.gz: 5c7f0c2b427a27bc2b6dd7f2b4248e47221207e9909ff4d4ed9a303bed8e8dad83f55fa36b2a2497be8eff84a55ea769abfdc49c100094d27c138a0b3db5de77
@@ -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
  #
@@ -13,10 +14,44 @@ require "webrick/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
@@ -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
  #
@@ -16,11 +17,17 @@ require 'webrick/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
  #
@@ -12,14 +13,56 @@ require 'time'
12
13
  require 'webrick/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
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: false
1
2
  #
2
3
  # httpauth.rb -- HTTP access authentication
3
4
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: false
1
2
  #--
2
3
  # httpauth/authenticator.rb -- Authenticator mix-in module.
3
4
  #
@@ -16,10 +17,10 @@ module WEBrick
16
17
 
17
18
  module Authenticator
18
19
 
19
- RequestField = "Authorization"
20
- ResponseField = "WWW-Authenticate"
21
- ResponseInfoField = "Authentication-Info"
22
- AuthException = HTTPStatus::Unauthorized
20
+ RequestField = "Authorization" # :nodoc:
21
+ ResponseField = "WWW-Authenticate" # :nodoc:
22
+ ResponseInfoField = "Authentication-Info" # :nodoc:
23
+ AuthException = HTTPStatus::Unauthorized # :nodoc:
23
24
 
24
25
  ##
25
26
  # Method of authentication, must be overridden by the including class
@@ -43,6 +44,8 @@ module WEBrick
43
44
 
44
45
  private
45
46
 
47
+ # :stopdoc:
48
+
46
49
  ##
47
50
  # Initializes the authenticator from +config+
48
51
 
@@ -96,6 +99,8 @@ module WEBrick
96
99
  log(:info, fmt, *args)
97
100
  end
98
101
  end
102
+
103
+ # :startdoc:
99
104
  end
100
105
 
101
106
  ##
@@ -103,10 +108,10 @@ module WEBrick
103
108
  # authentication schemes for proxies.
104
109
 
105
110
  module ProxyAuthenticator
106
- RequestField = "Proxy-Authorization"
107
- ResponseField = "Proxy-Authenticate"
108
- InfoField = "Proxy-Authentication-Info"
109
- AuthException = HTTPStatus::ProxyAuthenticationRequired
111
+ RequestField = "Proxy-Authorization" # :nodoc:
112
+ ResponseField = "Proxy-Authenticate" # :nodoc:
113
+ InfoField = "Proxy-Authentication-Info" # :nodoc:
114
+ AuthException = HTTPStatus::ProxyAuthenticationRequired # :nodoc:
110
115
  end
111
116
  end
112
117
  end