webrick 1.6.1 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/README.md +1 -3
- data/Rakefile +10 -3
- data/lib/webrick/accesslog.rb +1 -1
- data/lib/webrick/cgi.rb +1 -1
- data/lib/webrick/compat.rb +1 -1
- data/lib/webrick/config.rb +1 -1
- data/lib/webrick/cookie.rb +2 -2
- data/lib/webrick/htmlutils.rb +1 -1
- data/lib/webrick/httpauth/authenticator.rb +2 -2
- data/lib/webrick/httpauth/basicauth.rb +1 -1
- data/lib/webrick/httpauth/digestauth.rb +1 -1
- data/lib/webrick/httpauth/htdigest.rb +1 -1
- data/lib/webrick/httpauth/htgroup.rb +1 -1
- data/lib/webrick/httpauth/htpasswd.rb +1 -1
- data/lib/webrick/httpauth/userdb.rb +1 -1
- data/lib/webrick/httpauth.rb +1 -1
- data/lib/webrick/httpproxy.rb +7 -3
- data/lib/webrick/httprequest.rb +16 -7
- data/lib/webrick/httpresponse.rb +36 -12
- data/lib/webrick/https.rb +1 -1
- data/lib/webrick/httpserver.rb +2 -2
- data/lib/webrick/httpservlet/abstract.rb +1 -1
- data/lib/webrick/httpservlet/cgi_runner.rb +2 -2
- data/lib/webrick/httpservlet/cgihandler.rb +1 -1
- data/lib/webrick/httpservlet/erbhandler.rb +1 -1
- data/lib/webrick/httpservlet/filehandler.rb +20 -9
- data/lib/webrick/httpservlet/prochandler.rb +2 -1
- data/lib/webrick/httpservlet.rb +1 -1
- data/lib/webrick/httpstatus.rb +1 -1
- data/lib/webrick/httputils.rb +16 -4
- data/lib/webrick/httpversion.rb +1 -1
- data/lib/webrick/log.rb +7 -7
- data/lib/webrick/server.rb +4 -1
- data/lib/webrick/ssl.rb +19 -15
- data/lib/webrick/utils.rb +3 -8
- data/lib/webrick/version.rb +2 -2
- data/lib/webrick.rb +7 -2
- data/webrick.gemspec +4 -10
- metadata +8 -25
- data/bin/console +0 -14
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32a11a2138bc27a617a7f69e300868cc4957cd208e5358d17aa5d3135c645c1c
|
4
|
+
data.tar.gz: 3be4ec01ad7ae153f32db3ab01133c7f7e308e7f6bf984aed5eb08a0646622bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2eef98cfcc5a16f9da6b99e057ddbe5bb3bb00db407c259fc424092cdcefa94e3cec9dd82f71ab06fe9c423658ec0a4eb33a051f6bf9e3c034da19dc272449f
|
7
|
+
data.tar.gz: a0c44a9d8ca6e34666dd783941b908e7c7e496593f93b3f867cec75005b6727c3c7b276ee155e8eb2a886d2b90e47dbdf2ba42f97a1287addd34a76024502896
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# Webrick
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/ruby/webrick.svg?branch=master)](https://travis-ci.org/ruby/webrick)
|
4
|
-
|
5
3
|
WEBrick is an HTTP server toolkit that can be configured as an HTTPS server, a proxy server, and a virtual-host server.
|
6
4
|
|
7
5
|
WEBrick features complete logging of both server operations and HTTP access.
|
@@ -56,7 +54,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
56
54
|
|
57
55
|
## Contributing
|
58
56
|
|
59
|
-
Bug reports and
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/webrick.
|
60
58
|
|
61
59
|
## License
|
62
60
|
|
data/Rakefile
CHANGED
@@ -2,9 +2,16 @@ require "bundler/gem_tasks"
|
|
2
2
|
require "rake/testtask"
|
3
3
|
|
4
4
|
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs << "test
|
6
|
-
t.
|
7
|
-
t.test_files = FileList[
|
5
|
+
t.libs << "test/lib"
|
6
|
+
t.ruby_opts << "-rhelper"
|
7
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
8
|
+
end
|
9
|
+
|
10
|
+
task :sync_tool do
|
11
|
+
require 'fileutils'
|
12
|
+
FileUtils.cp "../ruby/tool/lib/core_assertions.rb", "./test/lib"
|
13
|
+
FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
|
14
|
+
FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
|
8
15
|
end
|
9
16
|
|
10
17
|
task :default => :test
|
data/lib/webrick/accesslog.rb
CHANGED
data/lib/webrick/cgi.rb
CHANGED
data/lib/webrick/compat.rb
CHANGED
data/lib/webrick/config.rb
CHANGED
data/lib/webrick/cookie.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# cookie.rb -- Cookie class
|
4
4
|
#
|
@@ -92,7 +92,7 @@ module WEBrick
|
|
92
92
|
# The cookie string suitable for use in an HTTP header
|
93
93
|
|
94
94
|
def to_s
|
95
|
-
ret = ""
|
95
|
+
ret = +""
|
96
96
|
ret << @name << "=" << @value
|
97
97
|
ret << "; " << "Version=" << @version.to_s if @version > 0
|
98
98
|
ret << "; " << "Domain=" << @domain if @domain
|
data/lib/webrick/htmlutils.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#--
|
3
3
|
# httpauth/authenticator.rb -- Authenticator mix-in module.
|
4
4
|
#
|
@@ -85,7 +85,7 @@ module WEBrick
|
|
85
85
|
def log(meth, fmt, *args)
|
86
86
|
msg = format("%s %s: ", @auth_scheme, @realm)
|
87
87
|
msg << fmt % args
|
88
|
-
@logger.
|
88
|
+
@logger.__send__(meth, msg)
|
89
89
|
end
|
90
90
|
|
91
91
|
def error(fmt, *args)
|
data/lib/webrick/httpauth.rb
CHANGED
data/lib/webrick/httpproxy.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# httpproxy.rb -- HTTPProxy Class
|
4
4
|
#
|
@@ -115,7 +115,7 @@ module WEBrick
|
|
115
115
|
proxy_auth(req, res)
|
116
116
|
|
117
117
|
begin
|
118
|
-
|
118
|
+
public_send("do_#{req.request_method}", req, res)
|
119
119
|
rescue NoMethodError
|
120
120
|
raise HTTPStatus::MethodNotAllowed,
|
121
121
|
"unsupported method `#{req.request_method}'."
|
@@ -295,6 +295,10 @@ module WEBrick
|
|
295
295
|
return FakeProxyURI
|
296
296
|
end
|
297
297
|
|
298
|
+
def create_net_http(uri, upstream)
|
299
|
+
Net::HTTP.new(uri.host, uri.port, upstream.host, upstream.port)
|
300
|
+
end
|
301
|
+
|
298
302
|
def perform_proxy_request(req, res, req_class, body_stream = nil)
|
299
303
|
uri = req.request_uri
|
300
304
|
path = uri.path.dup
|
@@ -303,7 +307,7 @@ module WEBrick
|
|
303
307
|
upstream = setup_upstream_proxy_authentication(req, res, header)
|
304
308
|
|
305
309
|
body_tmp = []
|
306
|
-
http =
|
310
|
+
http = create_net_http(uri, upstream)
|
307
311
|
req_fib = Fiber.new do
|
308
312
|
http.start do
|
309
313
|
if @config[:ProxyTimeout]
|
data/lib/webrick/httprequest.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# httprequest.rb -- HTTPRequest Class
|
4
4
|
#
|
@@ -9,6 +9,7 @@
|
|
9
9
|
#
|
10
10
|
# $IPR: httprequest.rb,v 1.64 2003/07/13 17:18:22 gotoyuzo Exp $
|
11
11
|
|
12
|
+
require 'fiber'
|
12
13
|
require 'uri'
|
13
14
|
require_relative 'httpversion'
|
14
15
|
require_relative 'httpstatus'
|
@@ -170,7 +171,7 @@ module WEBrick
|
|
170
171
|
@accept_charset = []
|
171
172
|
@accept_encoding = []
|
172
173
|
@accept_language = []
|
173
|
-
@body = ""
|
174
|
+
@body = +""
|
174
175
|
|
175
176
|
@addr = @peeraddr = nil
|
176
177
|
@attributes = {}
|
@@ -273,13 +274,17 @@ module WEBrick
|
|
273
274
|
self
|
274
275
|
end
|
275
276
|
|
276
|
-
# for IO.copy_stream.
|
277
|
-
# here; but IO.copy_stream does not care.
|
277
|
+
# for IO.copy_stream.
|
278
278
|
def readpartial(size, buf = ''.b) # :nodoc
|
279
279
|
res = @body_tmp.shift or raise EOFError, 'end of file reached'
|
280
|
+
if res.length > size
|
281
|
+
@body_tmp.unshift(res[size..-1])
|
282
|
+
res = res[0..size - 1]
|
283
|
+
end
|
280
284
|
buf.replace(res)
|
281
285
|
res.clear
|
282
|
-
|
286
|
+
# get more chunks - check alive? because we can take a partial chunk
|
287
|
+
@body_rd.resume if @body_rd.alive?
|
283
288
|
buf
|
284
289
|
end
|
285
290
|
|
@@ -486,8 +491,7 @@ module WEBrick
|
|
486
491
|
if @forwarded_host
|
487
492
|
host, port = @forwarded_host, @forwarded_port
|
488
493
|
elsif self["host"]
|
489
|
-
|
490
|
-
host, port = *self['host'].scan(pattern)[0]
|
494
|
+
host, port = parse_host_request_line(self["host"])
|
491
495
|
elsif @addr.size > 0
|
492
496
|
host, port = @addr[2], @addr[1]
|
493
497
|
else
|
@@ -499,6 +503,11 @@ module WEBrick
|
|
499
503
|
return URI::parse(uri.to_s)
|
500
504
|
end
|
501
505
|
|
506
|
+
def parse_host_request_line(host)
|
507
|
+
pattern = /\A(#{URI::REGEXP::PATTERN::HOST})(?::(\d+))?\z/no
|
508
|
+
host.scan(pattern)[0]
|
509
|
+
end
|
510
|
+
|
502
511
|
def read_body(socket, block)
|
503
512
|
return unless socket
|
504
513
|
if tc = self['transfer-encoding']
|
data/lib/webrick/httpresponse.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# httpresponse.rb -- HTTPResponse Class
|
4
4
|
#
|
@@ -105,6 +105,11 @@ module WEBrick
|
|
105
105
|
|
106
106
|
attr_reader :sent_size
|
107
107
|
|
108
|
+
##
|
109
|
+
# Set the response body proc as an streaming/upgrade response.
|
110
|
+
|
111
|
+
attr_accessor :upgrade
|
112
|
+
|
108
113
|
##
|
109
114
|
# Creates a new HTTP response object. WEBrick::Config::HTTP is the
|
110
115
|
# default configuration.
|
@@ -217,6 +222,16 @@ module WEBrick
|
|
217
222
|
@keep_alive
|
218
223
|
end
|
219
224
|
|
225
|
+
##
|
226
|
+
# Sets the response to be a streaming/upgrade response.
|
227
|
+
# This will disable keep-alive and chunked transfer encoding.
|
228
|
+
|
229
|
+
def upgrade!(protocol)
|
230
|
+
@upgrade = protocol
|
231
|
+
@keep_alive = false
|
232
|
+
@chunked = false
|
233
|
+
end
|
234
|
+
|
220
235
|
##
|
221
236
|
# Sends the response on +socket+
|
222
237
|
|
@@ -242,6 +257,14 @@ module WEBrick
|
|
242
257
|
@header['server'] ||= @config[:ServerSoftware]
|
243
258
|
@header['date'] ||= Time.now.httpdate
|
244
259
|
|
260
|
+
if @upgrade
|
261
|
+
@header['connection'] = 'upgrade'
|
262
|
+
@header['upgrade'] = @upgrade
|
263
|
+
@keep_alive = false
|
264
|
+
|
265
|
+
return
|
266
|
+
end
|
267
|
+
|
245
268
|
# HTTP/0.9 features
|
246
269
|
if @request_http_version < "1.0"
|
247
270
|
@http_version = HTTPVersion.new("0.9")
|
@@ -268,11 +291,10 @@ module WEBrick
|
|
268
291
|
elsif %r{^multipart/byteranges} =~ @header['content-type']
|
269
292
|
@header.delete('content-length')
|
270
293
|
elsif @header['content-length'].nil?
|
271
|
-
if @body.respond_to?
|
272
|
-
|
273
|
-
make_body_tempfile
|
294
|
+
if @body.respond_to?(:bytesize)
|
295
|
+
@header['content-length'] = @body.bytesize.to_s
|
274
296
|
else
|
275
|
-
@header['
|
297
|
+
@header['connection'] = 'close'
|
276
298
|
end
|
277
299
|
end
|
278
300
|
|
@@ -332,7 +354,7 @@ module WEBrick
|
|
332
354
|
|
333
355
|
def send_header(socket) # :nodoc:
|
334
356
|
if @http_version.major > 0
|
335
|
-
data = status_line()
|
357
|
+
data = status_line().dup
|
336
358
|
@header.each{|key, value|
|
337
359
|
tmp = key.gsub(/\bwww|^te$|\b\w/){ $&.upcase }
|
338
360
|
data << "#{tmp}: #{check_header(value)}" << CRLF
|
@@ -419,7 +441,7 @@ module WEBrick
|
|
419
441
|
# :stopdoc:
|
420
442
|
|
421
443
|
def error_body(backtrace, ex, host, port)
|
422
|
-
@body = ''
|
444
|
+
@body = +''
|
423
445
|
@body << <<-_end_of_html_
|
424
446
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
|
425
447
|
<HTML>
|
@@ -453,11 +475,11 @@ module WEBrick
|
|
453
475
|
if @request_method == "HEAD"
|
454
476
|
# do nothing
|
455
477
|
elsif chunked?
|
456
|
-
buf
|
478
|
+
buf = +''
|
457
479
|
begin
|
458
480
|
@body.readpartial(@buffer_size, buf)
|
459
481
|
size = buf.bytesize
|
460
|
-
data = "#{size.to_s(16)}#{CRLF}#{buf}#{CRLF}"
|
482
|
+
data = +"#{size.to_s(16)}#{CRLF}#{buf}#{CRLF}"
|
461
483
|
socket.write(data)
|
462
484
|
data.clear
|
463
485
|
@sent_size += size
|
@@ -517,14 +539,16 @@ module WEBrick
|
|
517
539
|
@body.call(ChunkedWrapper.new(socket, self))
|
518
540
|
socket.write("0#{CRLF}#{CRLF}")
|
519
541
|
else
|
520
|
-
size = @header['content-length'].to_i
|
521
542
|
if @bodytempfile
|
522
543
|
@bodytempfile.rewind
|
523
544
|
IO.copy_stream(@bodytempfile, socket)
|
524
545
|
else
|
525
546
|
@body.call(socket)
|
526
547
|
end
|
527
|
-
|
548
|
+
|
549
|
+
if content_length = @header['content-length']
|
550
|
+
@sent_size = content_length.to_i
|
551
|
+
end
|
528
552
|
end
|
529
553
|
end
|
530
554
|
|
@@ -539,7 +563,7 @@ module WEBrick
|
|
539
563
|
socket = @socket
|
540
564
|
@resp.instance_eval {
|
541
565
|
size = buf.bytesize
|
542
|
-
data = "#{size.to_s(16)}#{CRLF}#{buf}#{CRLF}"
|
566
|
+
data = +"#{size.to_s(16)}#{CRLF}#{buf}#{CRLF}"
|
543
567
|
socket.write(data)
|
544
568
|
data.clear
|
545
569
|
@sent_size += size
|
data/lib/webrick/https.rb
CHANGED
data/lib/webrick/httpserver.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# httpserver.rb -- HTTPServer Class
|
4
4
|
#
|
@@ -285,7 +285,7 @@ module WEBrick
|
|
285
285
|
end
|
286
286
|
|
287
287
|
def normalize(dir)
|
288
|
-
ret = dir ? dir.dup : ""
|
288
|
+
ret = dir ? dir.dup : +""
|
289
289
|
ret.sub!(%r|/+\z|, "")
|
290
290
|
ret
|
291
291
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# cgi_runner.rb -- CGI launcher.
|
4
4
|
#
|
@@ -10,7 +10,7 @@
|
|
10
10
|
# $IPR: cgi_runner.rb,v 1.9 2002/09/25 11:33:15 gotoyuzo Exp $
|
11
11
|
|
12
12
|
def sysread(io, size)
|
13
|
-
buf = ""
|
13
|
+
buf = +""
|
14
14
|
while size > 0
|
15
15
|
tmp = io.sysread(size)
|
16
16
|
buf << tmp
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# filehandler.rb -- FileHandler Module
|
4
4
|
#
|
@@ -212,9 +212,18 @@ module WEBrick
|
|
212
212
|
|
213
213
|
# :stopdoc:
|
214
214
|
|
215
|
+
def set_filesystem_encoding(str)
|
216
|
+
enc = Encoding.find('filesystem')
|
217
|
+
if enc == Encoding::US_ASCII
|
218
|
+
str.b
|
219
|
+
else
|
220
|
+
str.dup.force_encoding(enc)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
215
224
|
def service(req, res)
|
216
225
|
# if this class is mounted on "/" and /~username is requested.
|
217
|
-
# we're going to override path
|
226
|
+
# we're going to override path information before invoking service.
|
218
227
|
if defined?(Etc) && @options[:UserDir] && req.script_name.empty?
|
219
228
|
if %r|^(/~([^/]+))| =~ req.path_info
|
220
229
|
script_name, user = $1, $2
|
@@ -298,7 +307,7 @@ module WEBrick
|
|
298
307
|
end
|
299
308
|
|
300
309
|
def exec_handler(req, res)
|
301
|
-
raise HTTPStatus::NotFound, "`#{req.path}' not found" unless @root
|
310
|
+
raise HTTPStatus::NotFound, "`#{req.path}' not found." unless @root
|
302
311
|
if set_filename(req, res)
|
303
312
|
handler = get_handler(req, res)
|
304
313
|
call_callback(:HandlerCallback, req, res)
|
@@ -324,11 +333,12 @@ module WEBrick
|
|
324
333
|
end
|
325
334
|
|
326
335
|
def set_filename(req, res)
|
327
|
-
res.filename = @root
|
336
|
+
res.filename = @root
|
328
337
|
path_info = req.path_info.scan(%r|/[^/]*|)
|
329
338
|
|
330
339
|
path_info.unshift("") # dummy for checking @root dir
|
331
340
|
while base = path_info.first
|
341
|
+
base = set_filesystem_encoding(base)
|
332
342
|
break if base == "/"
|
333
343
|
break unless File.directory?(File.expand_path(res.filename + base))
|
334
344
|
shift_path_info(req, res, path_info)
|
@@ -336,6 +346,7 @@ module WEBrick
|
|
336
346
|
end
|
337
347
|
|
338
348
|
if base = path_info.first
|
349
|
+
base = set_filesystem_encoding(base)
|
339
350
|
if base == "/"
|
340
351
|
if file = search_index_file(req, res)
|
341
352
|
shift_path_info(req, res, path_info, file)
|
@@ -364,7 +375,7 @@ module WEBrick
|
|
364
375
|
|
365
376
|
def shift_path_info(req, res, path_info, base=nil)
|
366
377
|
tmp = path_info.shift
|
367
|
-
base = base || tmp
|
378
|
+
base = base || set_filesystem_encoding(tmp)
|
368
379
|
req.path_info = path_info.join
|
369
380
|
req.script_name << base
|
370
381
|
res.filename = File.expand_path(res.filename + base)
|
@@ -470,9 +481,9 @@ module WEBrick
|
|
470
481
|
elsif !namewidth or (namewidth = namewidth.to_i) < 2
|
471
482
|
namewidth = 25
|
472
483
|
end
|
473
|
-
query = query.inject('') {|s, (k, v)| s << '&' << HTMLUtils::escape("#{k}=#{v}")}
|
484
|
+
query = query.inject('') {|s, (k, v)| s << '&' << HTMLUtils::escape("#{k}=#{v}")}.dup
|
474
485
|
|
475
|
-
type = "text/html"
|
486
|
+
type = +"text/html"
|
476
487
|
case enc = Encoding.find('filesystem')
|
477
488
|
when Encoding::US_ASCII, Encoding::ASCII_8BIT
|
478
489
|
else
|
@@ -481,7 +492,7 @@ module WEBrick
|
|
481
492
|
res['content-type'] = type
|
482
493
|
|
483
494
|
title = "Index of #{HTMLUtils::escape(req.path)}"
|
484
|
-
res.body =
|
495
|
+
res.body = +<<-_end_of_html_
|
485
496
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
486
497
|
<HTML>
|
487
498
|
<HEAD>
|
@@ -517,7 +528,7 @@ module WEBrick
|
|
517
528
|
else
|
518
529
|
dname = name
|
519
530
|
end
|
520
|
-
s = "<TR><TD class=\"name\"><A HREF=\"#{HTTPUtils::escape(name)}#{query if name.end_with?('/')}\">#{HTMLUtils::escape(dname)}</A></TD>"
|
531
|
+
s = +"<TR><TD class=\"name\"><A HREF=\"#{HTTPUtils::escape(name)}#{query if name.end_with?('/')}\">#{HTMLUtils::escape(dname)}</A></TD>"
|
521
532
|
s << "<TD class=\"mtime\">" << (time ? time.strftime("%Y/%m/%d %H:%M") : "") << "</TD>"
|
522
533
|
s << "<TD class=\"size\">" << (size >= 0 ? size.to_s : "-") << "</TD></TR>\n"
|
523
534
|
res.body << s
|
data/lib/webrick/httpservlet.rb
CHANGED
data/lib/webrick/httpstatus.rb
CHANGED
data/lib/webrick/httputils.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# httputils.rb -- HTTPUtils Module
|
4
4
|
#
|
@@ -48,6 +48,7 @@ module WEBrick
|
|
48
48
|
"ai" => "application/postscript",
|
49
49
|
"asc" => "text/plain",
|
50
50
|
"avi" => "video/x-msvideo",
|
51
|
+
"avif" => "image/avif",
|
51
52
|
"bin" => "application/octet-stream",
|
52
53
|
"bmp" => "image/bmp",
|
53
54
|
"class" => "application/octet-stream",
|
@@ -65,6 +66,7 @@ module WEBrick
|
|
65
66
|
"gif" => "image/gif",
|
66
67
|
"htm" => "text/html",
|
67
68
|
"html" => "text/html",
|
69
|
+
"ico" => "image/x-icon",
|
68
70
|
"jpe" => "image/jpeg",
|
69
71
|
"jpeg" => "image/jpeg",
|
70
72
|
"jpg" => "image/jpeg",
|
@@ -72,10 +74,13 @@ module WEBrick
|
|
72
74
|
"json" => "application/json",
|
73
75
|
"lha" => "application/octet-stream",
|
74
76
|
"lzh" => "application/octet-stream",
|
77
|
+
"mjs" => "application/javascript",
|
75
78
|
"mov" => "video/quicktime",
|
79
|
+
"mp4" => "video/mp4",
|
76
80
|
"mpe" => "video/mpeg",
|
77
81
|
"mpeg" => "video/mpeg",
|
78
82
|
"mpg" => "video/mpeg",
|
83
|
+
"otf" => "font/otf",
|
79
84
|
"pbm" => "image/x-portable-bitmap",
|
80
85
|
"pdf" => "application/pdf",
|
81
86
|
"pgm" => "image/x-portable-graymap",
|
@@ -94,8 +99,15 @@ module WEBrick
|
|
94
99
|
"svg" => "image/svg+xml",
|
95
100
|
"tif" => "image/tiff",
|
96
101
|
"tiff" => "image/tiff",
|
102
|
+
"ttc" => "font/collection",
|
103
|
+
"ttf" => "font/ttf",
|
97
104
|
"txt" => "text/plain",
|
98
105
|
"wasm" => "application/wasm",
|
106
|
+
"webm" => "video/webm",
|
107
|
+
"webmanifest" => "application/manifest+json",
|
108
|
+
"webp" => "image/webp",
|
109
|
+
"woff" => "font/woff",
|
110
|
+
"woff2" => "font/woff2",
|
99
111
|
"xbm" => "image/x-xbitmap",
|
100
112
|
"xhtml" => "text/html",
|
101
113
|
"xls" => "application/vnd.ms-excel",
|
@@ -111,7 +123,7 @@ module WEBrick
|
|
111
123
|
def load_mime_types(file)
|
112
124
|
# note: +file+ may be a "| command" for now; some people may
|
113
125
|
# rely on this, but currently we do not use this method by default.
|
114
|
-
open(file){ |io|
|
126
|
+
File.open(file){ |io|
|
115
127
|
hash = Hash.new
|
116
128
|
io.each{ |line|
|
117
129
|
next if /^#/ =~ line
|
@@ -230,7 +242,7 @@ module WEBrick
|
|
230
242
|
# Quotes and escapes quotes in +str+
|
231
243
|
|
232
244
|
def quote(str)
|
233
|
-
'"' << str.gsub(/[\\\"]/o, "\\\1") << '"'
|
245
|
+
+'"' << str.gsub(/[\\\"]/o, "\\\1") << '"'
|
234
246
|
end
|
235
247
|
module_function :quote
|
236
248
|
|
@@ -494,7 +506,7 @@ module WEBrick
|
|
494
506
|
# Escapes path +str+
|
495
507
|
|
496
508
|
def escape_path(str)
|
497
|
-
result = ""
|
509
|
+
result = +""
|
498
510
|
str.scan(%r{/([^/]*)}).each{|i|
|
499
511
|
result << "/" << _escape(i[0], UNESCAPED_PCHAR)
|
500
512
|
}
|
data/lib/webrick/httpversion.rb
CHANGED
data/lib/webrick/log.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#--
|
3
3
|
# log.rb -- Log Class
|
4
4
|
#
|
@@ -86,15 +86,15 @@ module WEBrick
|
|
86
86
|
end
|
87
87
|
|
88
88
|
# Shortcut for logging a FATAL message
|
89
|
-
def fatal(msg) log(FATAL, "FATAL "
|
89
|
+
def fatal(msg) log(FATAL, "FATAL " + format(msg)); end
|
90
90
|
# Shortcut for logging an ERROR message
|
91
|
-
def error(msg) log(ERROR, "ERROR "
|
91
|
+
def error(msg) log(ERROR, "ERROR " + format(msg)); end
|
92
92
|
# Shortcut for logging a WARN message
|
93
|
-
def warn(msg) log(WARN, "WARN "
|
93
|
+
def warn(msg) log(WARN, "WARN " + format(msg)); end
|
94
94
|
# Shortcut for logging an INFO message
|
95
|
-
def info(msg) log(INFO, "INFO "
|
95
|
+
def info(msg) log(INFO, "INFO " + format(msg)); end
|
96
96
|
# Shortcut for logging a DEBUG message
|
97
|
-
def debug(msg) log(DEBUG, "DEBUG "
|
97
|
+
def debug(msg) log(DEBUG, "DEBUG " + format(msg)); end
|
98
98
|
|
99
99
|
# Will the logger output FATAL messages?
|
100
100
|
def fatal?; @level >= FATAL; end
|
@@ -118,7 +118,7 @@ module WEBrick
|
|
118
118
|
# * Otherwise it will return +arg+.inspect.
|
119
119
|
def format(arg)
|
120
120
|
if arg.is_a?(Exception)
|
121
|
-
"#{arg.class}: #{AccessLog.escape(arg.message)}\n\t" <<
|
121
|
+
+"#{arg.class}: #{AccessLog.escape(arg.message)}\n\t" <<
|
122
122
|
arg.backtrace.join("\n\t") << "\n"
|
123
123
|
elsif arg.respond_to?(:to_str)
|
124
124
|
AccessLog.escape(arg.to_str)
|
data/lib/webrick/server.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# server.rb -- GenericServer Class
|
4
4
|
#
|
@@ -102,6 +102,9 @@ module WEBrick
|
|
102
102
|
@listeners = []
|
103
103
|
@shutdown_pipe = nil
|
104
104
|
unless @config[:DoNotListen]
|
105
|
+
raise ArgumentError, "Port must be an integer" unless @config[:Port].to_s == @config[:Port].to_i.to_s
|
106
|
+
|
107
|
+
@config[:Port] = @config[:Port].to_i
|
105
108
|
if @config[:Listen]
|
106
109
|
warn(":Listen option is deprecated; use GenericServer#listen", uplevel: 1)
|
107
110
|
end
|
data/lib/webrick/ssl.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# ssl.rb -- SSL/TLS enhancement for GenericServer
|
4
4
|
#
|
@@ -95,18 +95,22 @@ module WEBrick
|
|
95
95
|
# the issuer +cn+ and a +comment+ to be stored in the certificate.
|
96
96
|
|
97
97
|
def create_self_signed_cert(bits, cn, comment)
|
98
|
-
rsa =
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
98
|
+
rsa = if $VERBOSE
|
99
|
+
OpenSSL::PKey::RSA.new(bits){|p, n|
|
100
|
+
case p
|
101
|
+
when 0; $stderr.putc "." # BN_generate_prime
|
102
|
+
when 1; $stderr.putc "+" # BN_generate_prime
|
103
|
+
when 2; $stderr.putc "*" # searching good prime,
|
104
|
+
# n = #of try,
|
105
|
+
# but also data from BN_generate_prime
|
106
|
+
when 3; $stderr.putc "\n" # found good prime, n==0 - p, n==1 - q,
|
107
|
+
# but also data from BN_generate_prime
|
108
|
+
else; $stderr.putc "*" # BN_generate_prime
|
109
|
+
end
|
110
|
+
}
|
111
|
+
else
|
112
|
+
OpenSSL::PKey::RSA.new(bits)
|
113
|
+
end
|
110
114
|
cert = OpenSSL::X509::Certificate.new
|
111
115
|
cert.version = 2
|
112
116
|
cert.serial = 1
|
@@ -122,7 +126,7 @@ module WEBrick
|
|
122
126
|
ef.issuer_certificate = cert
|
123
127
|
cert.extensions = [
|
124
128
|
ef.create_extension("basicConstraints","CA:FALSE"),
|
125
|
-
ef.create_extension("keyUsage", "keyEncipherment"),
|
129
|
+
ef.create_extension("keyUsage", "keyEncipherment, digitalSignature, keyAgreement, dataEncipherment"),
|
126
130
|
ef.create_extension("subjectKeyIdentifier", "hash"),
|
127
131
|
ef.create_extension("extendedKeyUsage", "serverAuth"),
|
128
132
|
ef.create_extension("nsComment", comment),
|
@@ -130,7 +134,7 @@ module WEBrick
|
|
130
134
|
aki = ef.create_extension("authorityKeyIdentifier",
|
131
135
|
"keyid:always,issuer:always")
|
132
136
|
cert.add_extension(aki)
|
133
|
-
cert.sign(rsa,
|
137
|
+
cert.sign(rsa, "SHA256")
|
134
138
|
|
135
139
|
return [ cert, rsa ]
|
136
140
|
end
|
data/lib/webrick/utils.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# frozen_string_literal:
|
1
|
+
# frozen_string_literal: true
|
2
2
|
#
|
3
3
|
# utils.rb -- Miscellaneous utilities
|
4
4
|
#
|
@@ -45,12 +45,7 @@ module WEBrick
|
|
45
45
|
##
|
46
46
|
# The server hostname
|
47
47
|
def getservername
|
48
|
-
|
49
|
-
begin
|
50
|
-
Socket::gethostbyname(host)[0]
|
51
|
-
rescue
|
52
|
-
host
|
53
|
-
end
|
48
|
+
Socket::gethostname
|
54
49
|
end
|
55
50
|
module_function :getservername
|
56
51
|
|
@@ -83,7 +78,7 @@ module WEBrick
|
|
83
78
|
# Generates a random string of length +len+
|
84
79
|
def random_string(len)
|
85
80
|
rand_max = RAND_CHARS.bytesize
|
86
|
-
ret = ""
|
81
|
+
ret = +""
|
87
82
|
len.times{ ret << RAND_CHARS[rand(rand_max)] }
|
88
83
|
ret
|
89
84
|
end
|
data/lib/webrick/version.rb
CHANGED
data/lib/webrick.rb
CHANGED
@@ -15,6 +15,11 @@
|
|
15
15
|
# WEBrick also includes tools for daemonizing a process and starting a process
|
16
16
|
# at a higher privilege level and dropping permissions.
|
17
17
|
#
|
18
|
+
# == Security
|
19
|
+
#
|
20
|
+
# *Warning:* WEBrick is not recommended for production. It only implements
|
21
|
+
# basic security checks.
|
22
|
+
#
|
18
23
|
# == Starting an HTTP server
|
19
24
|
#
|
20
25
|
# To create a new WEBrick::HTTPServer that will listen to connections on port
|
@@ -139,9 +144,9 @@
|
|
139
144
|
# servers. See WEBrick::HTTPAuth, WEBrick::HTTPAuth::BasicAuth and
|
140
145
|
# WEBrick::HTTPAuth::DigestAuth.
|
141
146
|
#
|
142
|
-
# == WEBrick as a
|
147
|
+
# == WEBrick as a daemonized Web Server
|
143
148
|
#
|
144
|
-
# WEBrick can be run as a
|
149
|
+
# WEBrick can be run as a daemonized server for small loads.
|
145
150
|
#
|
146
151
|
# === Daemonizing
|
147
152
|
#
|
data/webrick.gemspec
CHANGED
@@ -18,8 +18,6 @@ Gem::Specification.new do |s|
|
|
18
18
|
"LICENSE.txt",
|
19
19
|
"README.md",
|
20
20
|
"Rakefile",
|
21
|
-
"bin/console",
|
22
|
-
"bin/setup",
|
23
21
|
"lib/webrick.rb",
|
24
22
|
"lib/webrick/accesslog.rb",
|
25
23
|
"lib/webrick/cgi.rb",
|
@@ -57,20 +55,16 @@ Gem::Specification.new do |s|
|
|
57
55
|
"lib/webrick/version.rb",
|
58
56
|
"webrick.gemspec",
|
59
57
|
]
|
60
|
-
s.required_ruby_version = ">= 2.
|
58
|
+
s.required_ruby_version = ">= 2.4.0"
|
61
59
|
|
62
60
|
s.authors = ["TAKAHASHI Masayoshi", "GOTOU YUUZOU", "Eric Wong"]
|
63
61
|
s.email = [nil, nil, 'normal@ruby-lang.org']
|
64
|
-
s.homepage = "https://
|
65
|
-
s.
|
62
|
+
s.homepage = "https://github.com/ruby/webrick"
|
63
|
+
s.licenses = ["Ruby", "BSD-2-Clause"]
|
66
64
|
|
67
65
|
if s.respond_to?(:metadata=)
|
68
66
|
s.metadata = {
|
69
|
-
"bug_tracker_uri" => "https://
|
70
|
-
"homepage_uri" => "https://www.ruby-lang.org",
|
71
|
-
"source_code_uri" => "https://git.ruby-lang.org/ruby.git/"
|
67
|
+
"bug_tracker_uri" => "https://github.com/ruby/webrick/issues",
|
72
68
|
}
|
73
69
|
end
|
74
|
-
|
75
|
-
s.add_development_dependency "rake"
|
76
70
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webrick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TAKAHASHI Masayoshi
|
@@ -10,22 +10,8 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
14
|
-
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
16
|
-
name: rake
|
17
|
-
requirement: !ruby/object:Gem::Requirement
|
18
|
-
requirements:
|
19
|
-
- - ">="
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
requirements:
|
26
|
-
- - ">="
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
version: '0'
|
13
|
+
date: 2023-01-27 00:00:00.000000000 Z
|
14
|
+
dependencies: []
|
29
15
|
description: WEBrick is an HTTP server toolkit that can be configured as an HTTPS
|
30
16
|
server, a proxy server, and a virtual-host server.
|
31
17
|
email:
|
@@ -40,8 +26,6 @@ files:
|
|
40
26
|
- LICENSE.txt
|
41
27
|
- README.md
|
42
28
|
- Rakefile
|
43
|
-
- bin/console
|
44
|
-
- bin/setup
|
45
29
|
- lib/webrick.rb
|
46
30
|
- lib/webrick/accesslog.rb
|
47
31
|
- lib/webrick/cgi.rb
|
@@ -78,13 +62,12 @@ files:
|
|
78
62
|
- lib/webrick/utils.rb
|
79
63
|
- lib/webrick/version.rb
|
80
64
|
- webrick.gemspec
|
81
|
-
homepage: https://
|
65
|
+
homepage: https://github.com/ruby/webrick
|
82
66
|
licenses:
|
67
|
+
- Ruby
|
83
68
|
- BSD-2-Clause
|
84
69
|
metadata:
|
85
|
-
bug_tracker_uri: https://
|
86
|
-
homepage_uri: https://www.ruby-lang.org
|
87
|
-
source_code_uri: https://git.ruby-lang.org/ruby.git/
|
70
|
+
bug_tracker_uri: https://github.com/ruby/webrick/issues
|
88
71
|
post_install_message:
|
89
72
|
rdoc_options: []
|
90
73
|
require_paths:
|
@@ -93,14 +76,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
76
|
requirements:
|
94
77
|
- - ">="
|
95
78
|
- !ruby/object:Gem::Version
|
96
|
-
version: 2.
|
79
|
+
version: 2.4.0
|
97
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
81
|
requirements:
|
99
82
|
- - ">="
|
100
83
|
- !ruby/object:Gem::Version
|
101
84
|
version: '0'
|
102
85
|
requirements: []
|
103
|
-
rubygems_version: 3.
|
86
|
+
rubygems_version: 3.5.0.dev
|
104
87
|
signing_key:
|
105
88
|
specification_version: 4
|
106
89
|
summary: HTTP server toolkit
|
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "webrick"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|