webrick 1.3.1 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- 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 +7 -7
- data/lib/webrick/accesslog.rb +12 -6
- 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 +201 -31
- data/lib/webrick/httpresponse.rb +235 -70
- 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 +29 -11
- 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 +134 -17
- 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
- data/webrick.gemspec +76 -0
- metadata +73 -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: 3fb619ce6c4c78dad51be27360158b7e70c92ebdaa17c7b67b238c43ede73637
|
4
|
+
data.tar.gz: a9a2262fe7d36731d0d251c800a59d9f266a49811da67d8fb8240339cc1fe884
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 051dbf7d8f19f366b7713835c2cc37c9f8c53c58c0a4d68fc8256d277c2379bc90099437a48fb876e8d3b6c414c417f5d8b9cf092f372a9dd715a7771c6764fb
|
7
|
+
data.tar.gz: 7541dc4794d62c5c6363ccc7da3742e9d61216e5f9a4a3d94418dc3239830320b416eeb464940ad75074802f673055141b7c4937983ede6d1092a888fc6f5df0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
4
|
+
modification, are permitted provided that the following conditions
|
5
|
+
are met:
|
6
|
+
1. Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
|
+
2. Redistributions in binary form must reproduce the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
|
+
|
12
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
13
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
14
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
15
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
16
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
17
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
18
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
19
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
20
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
21
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
22
|
+
SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Webrick
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/ruby/webrick.svg?branch=master)](https://travis-ci.org/ruby/webrick)
|
4
|
+
|
5
|
+
WEBrick is an HTTP server toolkit that can be configured as an HTTPS server, a proxy server, and a virtual-host server.
|
6
|
+
|
7
|
+
WEBrick features complete logging of both server operations and HTTP access.
|
8
|
+
|
9
|
+
WEBrick supports both basic and digest authentication in addition to algorithms not in RFC 2617.
|
10
|
+
|
11
|
+
A WEBrick server can be composed of multiple WEBrick servers or servlets to provide differing behavior on a per-host or per-path basis. WEBrick includes servlets for handling CGI scripts, ERB pages, Ruby blocks and directory listings.
|
12
|
+
|
13
|
+
WEBrick also includes tools for daemonizing a process and starting a process at a higher privilege level and dropping permissions.
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'webrick'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install webrick
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
To create a new WEBrick::HTTPServer that will listen to connections on port 8000 and serve documents from the current user's public_html folder:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
require 'webrick'
|
37
|
+
|
38
|
+
root = File.expand_path '~/public_html'
|
39
|
+
server = WEBrick::HTTPServer.new :Port => 8000, :DocumentRoot => root
|
40
|
+
```
|
41
|
+
|
42
|
+
To run the server you will need to provide a suitable shutdown hook as
|
43
|
+
starting the server blocks the current thread:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
trap 'INT' do server.shutdown end
|
47
|
+
|
48
|
+
server.start
|
49
|
+
```
|
50
|
+
|
51
|
+
## Development
|
52
|
+
|
53
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
54
|
+
|
55
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
Bug reports and Patch are welcome on https://bugs.ruby-lang.org/.
|
60
|
+
|
61
|
+
## License
|
62
|
+
|
63
|
+
The gem is available as open source under the terms of the [2-Clause BSD License](https://opensource.org/licenses/BSD-2-Clause).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
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__)
|
data/bin/setup
ADDED
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
|
#
|
@@ -212,7 +212,7 @@ require 'webrick/version.rb'
|
|
212
212
|
require 'webrick/config.rb'
|
213
213
|
require 'webrick/log.rb'
|
214
214
|
require 'webrick/server.rb'
|
215
|
-
|
215
|
+
require_relative 'webrick/utils.rb'
|
216
216
|
require 'webrick/accesslog'
|
217
217
|
|
218
218
|
require 'webrick/htmlutils.rb'
|
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,12 +145,13 @@ module WEBrick
|
|
140
145
|
}
|
141
146
|
end
|
142
147
|
|
148
|
+
##
|
149
|
+
# Escapes control characters in +data+
|
150
|
+
|
143
151
|
def escape(data)
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
data
|
148
|
-
end
|
152
|
+
data = data.gsub(/[[:cntrl:]\\]+/) {$&.dump[1...-1]}
|
153
|
+
data.untaint if RUBY_VERSION < '2.7'
|
154
|
+
data
|
149
155
|
end
|
150
156
|
end
|
151
157
|
end
|
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
|
}
|