webrick 1.4.0 → 1.5.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.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +63 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/webrick.rb +1 -1
- data/lib/webrick/cgi.rb +7 -3
- data/lib/webrick/config.rb +5 -5
- data/lib/webrick/cookie.rb +1 -1
- data/lib/webrick/httpauth.rb +5 -5
- data/lib/webrick/httpauth/basicauth.rb +13 -5
- data/lib/webrick/httpauth/digestauth.rb +10 -23
- data/lib/webrick/httpauth/htdigest.rb +4 -4
- data/lib/webrick/httpauth/htgroup.rb +9 -6
- data/lib/webrick/httpauth/htpasswd.rb +39 -6
- data/lib/webrick/httpproxy.rb +44 -32
- data/lib/webrick/httprequest.rb +53 -14
- data/lib/webrick/httpresponse.rb +95 -50
- data/lib/webrick/https.rb +2 -2
- data/lib/webrick/httpserver.rb +23 -9
- data/lib/webrick/httpservlet.rb +5 -5
- data/lib/webrick/httpservlet/abstract.rb +3 -3
- data/lib/webrick/httpservlet/cgi_runner.rb +2 -2
- data/lib/webrick/httpservlet/cgihandler.rb +3 -5
- data/lib/webrick/httpservlet/erbhandler.rb +2 -2
- data/lib/webrick/httpservlet/filehandler.rb +49 -30
- data/lib/webrick/httpservlet/prochandler.rb +1 -1
- data/lib/webrick/httpstatus.rb +1 -1
- data/lib/webrick/httputils.rb +3 -0
- data/lib/webrick/log.rb +1 -1
- data/lib/webrick/server.rb +2 -2
- data/lib/webrick/ssl.rb +2 -2
- data/lib/webrick/version.rb +1 -1
- data/webrick.gemspec +76 -0
- metadata +17 -11
data/lib/webrick/https.rb
CHANGED
data/lib/webrick/httpserver.rb
CHANGED
@@ -10,13 +10,13 @@
|
|
10
10
|
# $IPR: httpserver.rb,v 1.63 2002/10/01 17:16:32 gotoyuzo Exp $
|
11
11
|
|
12
12
|
require 'io/wait'
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
require_relative 'server'
|
14
|
+
require_relative 'httputils'
|
15
|
+
require_relative 'httpstatus'
|
16
|
+
require_relative 'httprequest'
|
17
|
+
require_relative 'httpresponse'
|
18
|
+
require_relative 'httpservlet'
|
19
|
+
require_relative 'accesslog'
|
20
20
|
|
21
21
|
module WEBrick
|
22
22
|
class HTTPServerError < ServerError; end
|
@@ -68,8 +68,8 @@ module WEBrick
|
|
68
68
|
|
69
69
|
def run(sock)
|
70
70
|
while true
|
71
|
-
|
72
|
-
|
71
|
+
req = create_request(@config)
|
72
|
+
res = create_response(@config)
|
73
73
|
server = self
|
74
74
|
begin
|
75
75
|
timeout = @config[:RequestTimeout]
|
@@ -224,6 +224,20 @@ module WEBrick
|
|
224
224
|
}
|
225
225
|
end
|
226
226
|
|
227
|
+
##
|
228
|
+
# Creates the HTTPRequest used when handling the HTTP
|
229
|
+
# request. Can be overridden by subclasses.
|
230
|
+
def create_request(with_webrick_config)
|
231
|
+
HTTPRequest.new(with_webrick_config)
|
232
|
+
end
|
233
|
+
|
234
|
+
##
|
235
|
+
# Creates the HTTPResponse used when handling the HTTP
|
236
|
+
# request. Can be overridden by subclasses.
|
237
|
+
def create_response(with_webrick_config)
|
238
|
+
HTTPResponse.new(with_webrick_config)
|
239
|
+
end
|
240
|
+
|
227
241
|
##
|
228
242
|
# Mount table for the path a servlet is mounted on in the directory space
|
229
243
|
# of the server. Users of WEBrick can only access this indirectly via
|
data/lib/webrick/httpservlet.rb
CHANGED
@@ -9,11 +9,11 @@
|
|
9
9
|
#
|
10
10
|
# $IPR: httpservlet.rb,v 1.21 2003/02/23 12:24:46 gotoyuzo Exp $
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
require_relative 'httpservlet/abstract'
|
13
|
+
require_relative 'httpservlet/filehandler'
|
14
|
+
require_relative 'httpservlet/cgihandler'
|
15
|
+
require_relative 'httpservlet/erbhandler'
|
16
|
+
require_relative 'httpservlet/prochandler'
|
17
17
|
|
18
18
|
module WEBrick
|
19
19
|
module HTTPServlet
|
@@ -9,9 +9,9 @@
|
|
9
9
|
#
|
10
10
|
# $IPR: abstract.rb,v 1.24 2003/07/11 11:16:46 gotoyuzo Exp $
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
require_relative '../htmlutils'
|
13
|
+
require_relative '../httputils'
|
14
|
+
require_relative '../httpstatus'
|
15
15
|
|
16
16
|
module WEBrick
|
17
17
|
module HTTPServlet
|
@@ -23,11 +23,11 @@ STDIN.binmode
|
|
23
23
|
|
24
24
|
len = sysread(STDIN, 8).to_i
|
25
25
|
out = sysread(STDIN, len)
|
26
|
-
STDOUT.reopen(open(out, "w"))
|
26
|
+
STDOUT.reopen(File.open(out, "w"))
|
27
27
|
|
28
28
|
len = sysread(STDIN, 8).to_i
|
29
29
|
err = sysread(STDIN, len)
|
30
|
-
STDERR.reopen(open(err, "w"))
|
30
|
+
STDERR.reopen(File.open(err, "w"))
|
31
31
|
|
32
32
|
len = sysread(STDIN, 8).to_i
|
33
33
|
dump = sysread(STDIN, len)
|
@@ -11,8 +11,8 @@
|
|
11
11
|
|
12
12
|
require 'rbconfig'
|
13
13
|
require 'tempfile'
|
14
|
-
|
15
|
-
|
14
|
+
require_relative '../config'
|
15
|
+
require_relative 'abstract'
|
16
16
|
|
17
17
|
module WEBrick
|
18
18
|
module HTTPServlet
|
@@ -65,9 +65,7 @@ module WEBrick
|
|
65
65
|
cgi_in.write("%8d" % dump.bytesize)
|
66
66
|
cgi_in.write(dump)
|
67
67
|
|
68
|
-
|
69
|
-
cgi_in.write(req.body)
|
70
|
-
end
|
68
|
+
req.body { |chunk| cgi_in.write(chunk) }
|
71
69
|
ensure
|
72
70
|
cgi_in.close
|
73
71
|
status = $?.exitstatus
|
@@ -9,7 +9,7 @@
|
|
9
9
|
#
|
10
10
|
# $IPR: erbhandler.rb,v 1.25 2003/02/24 19:25:31 gotoyuzo Exp $
|
11
11
|
|
12
|
-
|
12
|
+
require_relative 'abstract'
|
13
13
|
|
14
14
|
require 'erb'
|
15
15
|
|
@@ -53,7 +53,7 @@ module WEBrick
|
|
53
53
|
raise HTTPStatus::Forbidden, "ERBHandler cannot work."
|
54
54
|
end
|
55
55
|
begin
|
56
|
-
data = open(@script_filename
|
56
|
+
data = File.open(@script_filename, &:read)
|
57
57
|
res.body = evaluate(ERB.new(data), req, res)
|
58
58
|
res['content-type'] ||=
|
59
59
|
HTTPUtils::mime_type(@script_filename, @config[:MimeTypes])
|
@@ -11,9 +11,9 @@
|
|
11
11
|
|
12
12
|
require 'time'
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
require_relative '../htmlutils'
|
15
|
+
require_relative '../httputils'
|
16
|
+
require_relative '../httpstatus'
|
17
17
|
|
18
18
|
module WEBrick
|
19
19
|
module HTTPServlet
|
@@ -55,9 +55,9 @@ module WEBrick
|
|
55
55
|
else
|
56
56
|
mtype = HTTPUtils::mime_type(@local_path, @config[:MimeTypes])
|
57
57
|
res['content-type'] = mtype
|
58
|
-
res['content-length'] = st.size
|
58
|
+
res['content-length'] = st.size.to_s
|
59
59
|
res['last-modified'] = mtime.httpdate
|
60
|
-
res.body = open(@local_path, "rb")
|
60
|
+
res.body = File.open(@local_path, "rb")
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -86,47 +86,66 @@ module WEBrick
|
|
86
86
|
return false
|
87
87
|
end
|
88
88
|
|
89
|
+
# returns a lambda for webrick/httpresponse.rb send_body_proc
|
90
|
+
def multipart_body(body, parts, boundary, mtype, filesize)
|
91
|
+
lambda do |socket|
|
92
|
+
begin
|
93
|
+
begin
|
94
|
+
first = parts.shift
|
95
|
+
last = parts.shift
|
96
|
+
socket.write(
|
97
|
+
"--#{boundary}#{CRLF}" \
|
98
|
+
"Content-Type: #{mtype}#{CRLF}" \
|
99
|
+
"Content-Range: bytes #{first}-#{last}/#{filesize}#{CRLF}" \
|
100
|
+
"#{CRLF}"
|
101
|
+
)
|
102
|
+
|
103
|
+
begin
|
104
|
+
IO.copy_stream(body, socket, last - first + 1, first)
|
105
|
+
rescue NotImplementedError
|
106
|
+
body.seek(first, IO::SEEK_SET)
|
107
|
+
IO.copy_stream(body, socket, last - first + 1)
|
108
|
+
end
|
109
|
+
socket.write(CRLF)
|
110
|
+
end while parts[0]
|
111
|
+
socket.write("--#{boundary}--#{CRLF}")
|
112
|
+
ensure
|
113
|
+
body.close
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
89
118
|
def make_partial_content(req, res, filename, filesize)
|
90
119
|
mtype = HTTPUtils::mime_type(filename, @config[:MimeTypes])
|
91
120
|
unless ranges = HTTPUtils::parse_range_header(req['range'])
|
92
121
|
raise HTTPStatus::BadRequest,
|
93
122
|
"Unrecognized range-spec: \"#{req['range']}\""
|
94
123
|
end
|
95
|
-
open(filename, "rb"){|io|
|
124
|
+
File.open(filename, "rb"){|io|
|
96
125
|
if ranges.size > 1
|
97
126
|
time = Time.now
|
98
127
|
boundary = "#{time.sec}_#{time.usec}_#{Process::pid}"
|
99
|
-
|
100
|
-
ranges.each{|range|
|
101
|
-
|
102
|
-
next if
|
103
|
-
|
104
|
-
content = io.read(last-first+1)
|
105
|
-
body << "--" << boundary << CRLF
|
106
|
-
body << "Content-Type: #{mtype}" << CRLF
|
107
|
-
body << "Content-Range: bytes #{first}-#{last}/#{filesize}" << CRLF
|
108
|
-
body << CRLF
|
109
|
-
body << content
|
110
|
-
body << CRLF
|
128
|
+
parts = []
|
129
|
+
ranges.each {|range|
|
130
|
+
prange = prepare_range(range, filesize)
|
131
|
+
next if prange[0] < 0
|
132
|
+
parts.concat(prange)
|
111
133
|
}
|
112
|
-
raise HTTPStatus::RequestRangeNotSatisfiable if
|
113
|
-
body << "--" << boundary << "--" << CRLF
|
134
|
+
raise HTTPStatus::RequestRangeNotSatisfiable if parts.empty?
|
114
135
|
res["content-type"] = "multipart/byteranges; boundary=#{boundary}"
|
115
|
-
|
136
|
+
if req.http_version < '1.1'
|
137
|
+
res['connection'] = 'close'
|
138
|
+
else
|
139
|
+
res.chunked = true
|
140
|
+
end
|
141
|
+
res.body = multipart_body(io.dup, parts, boundary, mtype, filesize)
|
116
142
|
elsif range = ranges[0]
|
117
143
|
first, last = prepare_range(range, filesize)
|
118
144
|
raise HTTPStatus::RequestRangeNotSatisfiable if first < 0
|
119
|
-
if last == filesize - 1
|
120
|
-
content = io.dup
|
121
|
-
content.pos = first
|
122
|
-
else
|
123
|
-
io.pos = first
|
124
|
-
content = io.read(last-first+1)
|
125
|
-
end
|
126
145
|
res['content-type'] = mtype
|
127
146
|
res['content-range'] = "bytes #{first}-#{last}/#{filesize}"
|
128
|
-
res['content-length'] = last - first + 1
|
129
|
-
res.body =
|
147
|
+
res['content-length'] = (last - first + 1).to_s
|
148
|
+
res.body = io.dup
|
130
149
|
else
|
131
150
|
raise HTTPStatus::BadRequest
|
132
151
|
end
|
data/lib/webrick/httpstatus.rb
CHANGED
data/lib/webrick/httputils.rb
CHANGED
@@ -95,6 +95,7 @@ module WEBrick
|
|
95
95
|
"tif" => "image/tiff",
|
96
96
|
"tiff" => "image/tiff",
|
97
97
|
"txt" => "text/plain",
|
98
|
+
"wasm" => "application/wasm",
|
98
99
|
"xbm" => "image/x-xbitmap",
|
99
100
|
"xhtml" => "text/html",
|
100
101
|
"xls" => "application/vnd.ms-excel",
|
@@ -108,6 +109,8 @@ module WEBrick
|
|
108
109
|
# Loads Apache-compatible mime.types in +file+.
|
109
110
|
|
110
111
|
def load_mime_types(file)
|
112
|
+
# note: +file+ may be a "| command" for now; some people may
|
113
|
+
# rely on this, but currently we do not use this method by default.
|
111
114
|
open(file){ |io|
|
112
115
|
hash = Hash.new
|
113
116
|
io.each{ |line|
|
data/lib/webrick/log.rb
CHANGED
data/lib/webrick/server.rb
CHANGED
data/lib/webrick/ssl.rb
CHANGED
@@ -130,7 +130,7 @@ module WEBrick
|
|
130
130
|
aki = ef.create_extension("authorityKeyIdentifier",
|
131
131
|
"keyid:always,issuer:always")
|
132
132
|
cert.add_extension(aki)
|
133
|
-
cert.sign(rsa, OpenSSL::Digest::
|
133
|
+
cert.sign(rsa, OpenSSL::Digest::SHA256.new)
|
134
134
|
|
135
135
|
return [ cert, rsa ]
|
136
136
|
end
|
@@ -181,7 +181,7 @@ module WEBrick
|
|
181
181
|
unless config[:SSLCertificate]
|
182
182
|
cn = config[:SSLCertName]
|
183
183
|
comment = config[:SSLCertComment]
|
184
|
-
cert, key = Utils::create_self_signed_cert(
|
184
|
+
cert, key = Utils::create_self_signed_cert(2048, cn, comment)
|
185
185
|
config[:SSLCertificate] = cert
|
186
186
|
config[:SSLPrivateKey] = key
|
187
187
|
end
|
data/lib/webrick/version.rb
CHANGED
data/webrick.gemspec
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
begin
|
3
|
+
require_relative 'lib/webrick/version'
|
4
|
+
rescue LoadError
|
5
|
+
# for Ruby core repository
|
6
|
+
require_relative 'version'
|
7
|
+
end
|
8
|
+
|
9
|
+
Gem::Specification.new do |s|
|
10
|
+
s.name = "webrick"
|
11
|
+
s.version = WEBrick::VERSION
|
12
|
+
s.summary = "HTTP server toolkit"
|
13
|
+
s.description = "WEBrick is an HTTP server toolkit that can be configured as an HTTPS server, a proxy server, and a virtual-host server."
|
14
|
+
|
15
|
+
s.require_path = %w{lib}
|
16
|
+
s.files = [
|
17
|
+
"Gemfile",
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.md",
|
20
|
+
"Rakefile",
|
21
|
+
"bin/console",
|
22
|
+
"bin/setup",
|
23
|
+
"lib/webrick.rb",
|
24
|
+
"lib/webrick/accesslog.rb",
|
25
|
+
"lib/webrick/cgi.rb",
|
26
|
+
"lib/webrick/compat.rb",
|
27
|
+
"lib/webrick/config.rb",
|
28
|
+
"lib/webrick/cookie.rb",
|
29
|
+
"lib/webrick/htmlutils.rb",
|
30
|
+
"lib/webrick/httpauth.rb",
|
31
|
+
"lib/webrick/httpauth/authenticator.rb",
|
32
|
+
"lib/webrick/httpauth/basicauth.rb",
|
33
|
+
"lib/webrick/httpauth/digestauth.rb",
|
34
|
+
"lib/webrick/httpauth/htdigest.rb",
|
35
|
+
"lib/webrick/httpauth/htgroup.rb",
|
36
|
+
"lib/webrick/httpauth/htpasswd.rb",
|
37
|
+
"lib/webrick/httpauth/userdb.rb",
|
38
|
+
"lib/webrick/httpproxy.rb",
|
39
|
+
"lib/webrick/httprequest.rb",
|
40
|
+
"lib/webrick/httpresponse.rb",
|
41
|
+
"lib/webrick/https.rb",
|
42
|
+
"lib/webrick/httpserver.rb",
|
43
|
+
"lib/webrick/httpservlet.rb",
|
44
|
+
"lib/webrick/httpservlet/abstract.rb",
|
45
|
+
"lib/webrick/httpservlet/cgi_runner.rb",
|
46
|
+
"lib/webrick/httpservlet/cgihandler.rb",
|
47
|
+
"lib/webrick/httpservlet/erbhandler.rb",
|
48
|
+
"lib/webrick/httpservlet/filehandler.rb",
|
49
|
+
"lib/webrick/httpservlet/prochandler.rb",
|
50
|
+
"lib/webrick/httpstatus.rb",
|
51
|
+
"lib/webrick/httputils.rb",
|
52
|
+
"lib/webrick/httpversion.rb",
|
53
|
+
"lib/webrick/log.rb",
|
54
|
+
"lib/webrick/server.rb",
|
55
|
+
"lib/webrick/ssl.rb",
|
56
|
+
"lib/webrick/utils.rb",
|
57
|
+
"lib/webrick/version.rb",
|
58
|
+
"webrick.gemspec",
|
59
|
+
]
|
60
|
+
s.required_ruby_version = ">= 2.3.0"
|
61
|
+
|
62
|
+
s.authors = ["TAKAHASHI Masayoshi", "GOTOU YUUZOU", "Eric Wong"]
|
63
|
+
s.email = [nil, nil, 'normal@ruby-lang.org']
|
64
|
+
s.homepage = "https://www.ruby-lang.org"
|
65
|
+
s.license = "BSD-2-Clause"
|
66
|
+
|
67
|
+
if s.respond_to?(:metadata=)
|
68
|
+
s.metadata = {
|
69
|
+
"bug_tracker_uri" => "https://bugs.ruby-lang.org/projects/ruby-trunk/issues",
|
70
|
+
"homepage_uri" => "https://www.ruby-lang.org",
|
71
|
+
"source_code_uri" => "https://git.ruby-lang.org/ruby.git/"
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
s.add_development_dependency "rake"
|
76
|
+
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webrick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TAKAHASHI Masayoshi
|
8
8
|
- GOTOU YUUZOU
|
9
9
|
- Eric Wong
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2020-09-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -29,13 +29,19 @@ dependencies:
|
|
29
29
|
description: WEBrick is an HTTP server toolkit that can be configured as an HTTPS
|
30
30
|
server, a proxy server, and a virtual-host server.
|
31
31
|
email:
|
32
|
-
-
|
33
|
-
-
|
32
|
+
-
|
33
|
+
-
|
34
34
|
- normal@ruby-lang.org
|
35
35
|
executables: []
|
36
36
|
extensions: []
|
37
37
|
extra_rdoc_files: []
|
38
38
|
files:
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- bin/console
|
44
|
+
- bin/setup
|
39
45
|
- lib/webrick.rb
|
40
46
|
- lib/webrick/accesslog.rb
|
41
47
|
- lib/webrick/cgi.rb
|
@@ -71,14 +77,15 @@ files:
|
|
71
77
|
- lib/webrick/ssl.rb
|
72
78
|
- lib/webrick/utils.rb
|
73
79
|
- lib/webrick/version.rb
|
80
|
+
- webrick.gemspec
|
74
81
|
homepage: https://www.ruby-lang.org
|
75
82
|
licenses:
|
76
83
|
- BSD-2-Clause
|
77
84
|
metadata:
|
78
85
|
bug_tracker_uri: https://bugs.ruby-lang.org/projects/ruby-trunk/issues
|
79
86
|
homepage_uri: https://www.ruby-lang.org
|
80
|
-
source_code_uri: https://
|
81
|
-
post_install_message:
|
87
|
+
source_code_uri: https://git.ruby-lang.org/ruby.git/
|
88
|
+
post_install_message:
|
82
89
|
rdoc_options: []
|
83
90
|
require_paths:
|
84
91
|
- lib
|
@@ -86,16 +93,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
93
|
requirements:
|
87
94
|
- - ">="
|
88
95
|
- !ruby/object:Gem::Version
|
89
|
-
version: 2.
|
96
|
+
version: 2.3.0
|
90
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
98
|
requirements:
|
92
99
|
- - ">="
|
93
100
|
- !ruby/object:Gem::Version
|
94
101
|
version: '0'
|
95
102
|
requirements: []
|
96
|
-
|
97
|
-
|
98
|
-
signing_key:
|
103
|
+
rubygems_version: 3.2.0.rc.1
|
104
|
+
signing_key:
|
99
105
|
specification_version: 4
|
100
106
|
summary: HTTP server toolkit
|
101
107
|
test_files: []
|