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
checksums.yaml
ADDED
@@ -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
|
data/lib/webrick.rb
CHANGED
@@ -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
|
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,
|
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
|
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
|
-
#
|
133
|
-
#
|
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
|
#
|
data/lib/webrick/accesslog.rb
CHANGED
@@ -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
|
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
|
data/lib/webrick/cgi.rb
CHANGED
@@ -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
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
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
|
-
|
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"]
|
data/lib/webrick/compat.rb
CHANGED
@@ -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
|
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
|
data/lib/webrick/config.rb
CHANGED
@@ -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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
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 =>
|
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
|
}
|
data/lib/webrick/cookie.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
54
|
-
#
|
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(
|
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)
|
data/lib/webrick/htmlutils.rb
CHANGED
@@ -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
|
-
|
19
|
+
return "" unless string
|
20
|
+
str = string.b
|
19
21
|
str.gsub!(/&/n, '&')
|
20
22
|
str.gsub!(/\"/n, '"')
|
21
23
|
str.gsub!(/>/n, '>')
|
22
24
|
str.gsub!(/</n, '<')
|
23
|
-
str
|
25
|
+
str.force_encoding(string.encoding)
|
24
26
|
end
|
25
27
|
module_function :escape
|
26
28
|
|