-
-
Save headius/bab5b016f9088ef85857620e6305f461 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Only in ../ruby/lib/webrick: .document | |
diff -u lib/webrick/accesslog.rb ../ruby/lib/webrick/accesslog.rb | |
--- lib/webrick/accesslog.rb 2020-06-29 23:37:23.000000000 -0500 | |
+++ ../ruby/lib/webrick/accesslog.rb 2020-06-30 14:34:33.000000000 -0500 | |
@@ -149,9 +149,11 @@ | |
# Escapes control characters in +data+ | |
def escape(data) | |
- data = data.gsub(/[[:cntrl:]\\]+/) {$&.dump[1...-1]} | |
- data.untaint if RUBY_VERSION < '2.7' | |
- data | |
+ if data.tainted? | |
+ data.gsub(/[[:cntrl:]\\]+/) {$&.dump[1...-1]}.untaint | |
+ else | |
+ data | |
+ end | |
end | |
end | |
end | |
diff -u lib/webrick/cgi.rb ../ruby/lib/webrick/cgi.rb | |
--- lib/webrick/cgi.rb 2020-06-29 23:36:38.000000000 -0500 | |
+++ ../ruby/lib/webrick/cgi.rb 2020-06-30 14:34:33.000000000 -0500 | |
@@ -8,9 +8,9 @@ | |
# | |
# $Id$ | |
-require_relative "httprequest" | |
-require_relative "httpresponse" | |
-require_relative "config" | |
+require "webrick/httprequest" | |
+require "webrick/httpresponse" | |
+require "webrick/config" | |
require "stringio" | |
module WEBrick | |
diff -u lib/webrick/config.rb ../ruby/lib/webrick/config.rb | |
--- lib/webrick/config.rb 2020-06-29 23:36:38.000000000 -0500 | |
+++ ../ruby/lib/webrick/config.rb 2020-06-30 14:34:33.000000000 -0500 | |
@@ -9,11 +9,11 @@ | |
# | |
# $IPR: config.rb,v 1.52 2003/07/22 19:20:42 gotoyuzo Exp $ | |
-require_relative 'version' | |
-require_relative 'httpversion' | |
-require_relative 'httputils' | |
-require_relative 'utils' | |
-require_relative 'log' | |
+require 'webrick/version' | |
+require 'webrick/httpversion' | |
+require 'webrick/httputils' | |
+require 'webrick/utils' | |
+require 'webrick/log' | |
module WEBrick | |
module Config | |
diff -u lib/webrick/cookie.rb ../ruby/lib/webrick/cookie.rb | |
--- lib/webrick/cookie.rb 2020-06-29 23:36:38.000000000 -0500 | |
+++ ../ruby/lib/webrick/cookie.rb 2020-06-30 14:34:33.000000000 -0500 | |
@@ -10,7 +10,7 @@ | |
# $IPR: cookie.rb,v 1.16 2002/09/21 12:23:35 gotoyuzo Exp $ | |
require 'time' | |
-require_relative 'httputils' | |
+require 'webrick/httputils' | |
module WEBrick | |
Common subdirectories: lib/webrick/httpauth and ../ruby/lib/webrick/httpauth | |
diff -u lib/webrick/httpauth.rb ../ruby/lib/webrick/httpauth.rb | |
--- lib/webrick/httpauth.rb 2020-06-29 23:36:38.000000000 -0500 | |
+++ ../ruby/lib/webrick/httpauth.rb 2020-06-30 14:34:33.000000000 -0500 | |
@@ -9,11 +9,11 @@ | |
# | |
# $IPR: httpauth.rb,v 1.14 2003/07/22 19:20:42 gotoyuzo Exp $ | |
-require_relative 'httpauth/basicauth' | |
-require_relative 'httpauth/digestauth' | |
-require_relative 'httpauth/htpasswd' | |
-require_relative 'httpauth/htdigest' | |
-require_relative 'httpauth/htgroup' | |
+require 'webrick/httpauth/basicauth' | |
+require 'webrick/httpauth/digestauth' | |
+require 'webrick/httpauth/htpasswd' | |
+require 'webrick/httpauth/htdigest' | |
+require 'webrick/httpauth/htgroup' | |
module WEBrick | |
diff -u lib/webrick/httpproxy.rb ../ruby/lib/webrick/httpproxy.rb | |
--- lib/webrick/httpproxy.rb 2020-06-30 14:19:23.000000000 -0500 | |
+++ ../ruby/lib/webrick/httpproxy.rb 2020-06-30 14:34:33.000000000 -0500 | |
@@ -10,7 +10,7 @@ | |
# $IPR: httpproxy.rb,v 1.18 2003/03/08 18:58:10 gotoyuzo Exp $ | |
# $kNotwork: straw.rb,v 1.3 2002/02/12 15:13:07 gotoken Exp $ | |
-require_relative "httpserver" | |
+require "webrick/httpserver" | |
require "net/http" | |
module WEBrick | |
@@ -211,15 +211,21 @@ | |
end | |
def do_GET(req, res) | |
- perform_proxy_request(req, res, Net::HTTP::Get) | |
+ perform_proxy_request(req, res) do |http, path, header| | |
+ http.get(path, header) | |
+ end | |
end | |
def do_HEAD(req, res) | |
- perform_proxy_request(req, res, Net::HTTP::Head) | |
+ perform_proxy_request(req, res) do |http, path, header| | |
+ http.head(path, header) | |
+ end | |
end | |
def do_POST(req, res) | |
- perform_proxy_request(req, res, Net::HTTP::Post, req.body_reader) | |
+ perform_proxy_request(req, res) do |http, path, header| | |
+ http.post(path, req.body || "", header) | |
+ end | |
end | |
def do_OPTIONS(req, res) | |
@@ -295,56 +301,38 @@ | |
return FakeProxyURI | |
end | |
- def perform_proxy_request(req, res, req_class, body_stream = nil) | |
+ def perform_proxy_request(req, res) | |
uri = req.request_uri | |
path = uri.path.dup | |
path << "?" << uri.query if uri.query | |
header = setup_proxy_header(req, res) | |
upstream = setup_upstream_proxy_authentication(req, res, header) | |
+ response = nil | |
- body_tmp = [] | |
http = Net::HTTP.new(uri.host, uri.port, upstream.host, upstream.port) | |
- req_fib = Fiber.new do | |
- http.start do | |
- if @config[:ProxyTimeout] | |
- ################################## these issues are | |
- http.open_timeout = 30 # secs # necessary (maybe because | |
- http.read_timeout = 60 # secs # Ruby's bug, but why?) | |
- ################################## | |
- end | |
- if body_stream && req['transfer-encoding'] =~ /\bchunked\b/i | |
- header['Transfer-Encoding'] = 'chunked' | |
- end | |
- http_req = req_class.new(path, header) | |
- http_req.body_stream = body_stream if body_stream | |
- http.request(http_req) do |response| | |
- # Persistent connection requirements are mysterious for me. | |
- # So I will close the connection in every response. | |
- res['proxy-connection'] = "close" | |
- res['connection'] = "close" | |
- | |
- # stream Net::HTTP::HTTPResponse to WEBrick::HTTPResponse | |
- res.status = response.code.to_i | |
- res.chunked = response.chunked? | |
- choose_header(response, res) | |
- set_cookie(response, res) | |
- set_via(res) | |
- response.read_body do |buf| | |
- body_tmp << buf | |
- Fiber.yield # wait for res.body Proc#call | |
- end | |
- end # http.request | |
- end | |
- end | |
- req_fib.resume # read HTTP response headers and first chunk of the body | |
- res.body = ->(socket) do | |
- while buf = body_tmp.shift | |
- socket.write(buf) | |
- buf.clear | |
- req_fib.resume # continue response.read_body | |
+ http.start do | |
+ if @config[:ProxyTimeout] | |
+ ################################## these issues are | |
+ http.open_timeout = 30 # secs # necessary (maybe because | |
+ http.read_timeout = 60 # secs # Ruby's bug, but why?) | |
+ ################################## | |
end | |
+ response = yield(http, path, header) | |
end | |
+ | |
+ # Persistent connection requirements are mysterious for me. | |
+ # So I will close the connection in every response. | |
+ res['proxy-connection'] = "close" | |
+ res['connection'] = "close" | |
+ | |
+ # Convert Net::HTTP::HTTPResponse to WEBrick::HTTPResponse | |
+ res.status = response.code.to_i | |
+ choose_header(response, res) | |
+ set_cookie(response, res) | |
+ set_via(res) | |
+ res.body = response.body | |
end | |
+ | |
# :stopdoc: | |
end | |
end | |
diff -u lib/webrick/httprequest.rb ../ruby/lib/webrick/httprequest.rb | |
--- lib/webrick/httprequest.rb 2020-06-29 23:37:23.000000000 -0500 | |
+++ ../ruby/lib/webrick/httprequest.rb 2020-06-30 14:34:33.000000000 -0500 | |
@@ -10,10 +10,10 @@ | |
# $IPR: httprequest.rb,v 1.64 2003/07/13 17:18:22 gotoyuzo Exp $ | |
require 'uri' | |
-require_relative 'httpversion' | |
-require_relative 'httpstatus' | |
-require_relative 'httputils' | |
-require_relative 'cookie' | |
+require 'webrick/httpversion' | |
+require 'webrick/httpstatus' | |
+require 'webrick/httputils' | |
+require 'webrick/cookie' | |
module WEBrick | |
@@ -258,32 +258,6 @@ | |
end | |
## | |
- # Prepares the HTTPRequest object for use as the | |
- # source for IO.copy_stream | |
- | |
- def body_reader | |
- @body_tmp = [] | |
- @body_rd = Fiber.new do | |
- body do |buf| | |
- @body_tmp << buf | |
- Fiber.yield | |
- end | |
- end | |
- @body_rd.resume # grab the first chunk and yield | |
- self | |
- end | |
- | |
- # for IO.copy_stream. Note: we may return a larger string than +size+ | |
- # here; but IO.copy_stream does not care. | |
- def readpartial(size, buf = ''.b) # :nodoc | |
- res = @body_tmp.shift or raise EOFError, 'end of file reached' | |
- buf.replace(res) | |
- res.clear | |
- @body_rd.resume # get more chunks | |
- buf | |
- end | |
- | |
- ## | |
# Request query as a Hash | |
def query | |
@@ -445,14 +419,12 @@ | |
def read_request_line(socket) | |
@request_line = read_line(socket, MAX_URI_LENGTH) if socket | |
- raise HTTPStatus::EOFError unless @request_line | |
- | |
@request_bytes = @request_line.bytesize | |
if @request_bytes >= MAX_URI_LENGTH and @request_line[-1, 1] != LF | |
raise HTTPStatus::RequestURITooLarge | |
end | |
- | |
@request_time = Time.now | |
+ raise HTTPStatus::EOFError unless @request_line | |
if /^(\S+)\s+(\S++)(?:\s+HTTP\/(\d+\.\d+))?\r?\n/mo =~ @request_line | |
@request_method = $1 | |
@unparsed_uri = $2 | |
@@ -611,12 +583,7 @@ | |
end | |
if host_port = self["x-forwarded-host"] | |
host_port = host_port.split(",", 2).first | |
- if host_port =~ /\A(\[[0-9a-fA-F:]+\])(?::(\d+))?\z/ | |
- @forwarded_host = $1 | |
- tmp = $2 | |
- else | |
- @forwarded_host, tmp = host_port.split(":", 2) | |
- end | |
+ @forwarded_host, tmp = host_port.split(":", 2) | |
@forwarded_port = (tmp || (@forwarded_proto == "https" ? 443 : 80)).to_i | |
end | |
if addrs = self["x-forwarded-for"] | |
diff -u lib/webrick/httpresponse.rb ../ruby/lib/webrick/httpresponse.rb | |
--- lib/webrick/httpresponse.rb 2020-06-29 23:37:23.000000000 -0500 | |
+++ ../ruby/lib/webrick/httpresponse.rb 2020-06-30 14:34:33.000000000 -0500 | |
@@ -10,11 +10,10 @@ | |
# $IPR: httpresponse.rb,v 1.45 2003/07/11 11:02:25 gotoyuzo Exp $ | |
require 'time' | |
-require 'uri' | |
-require_relative 'httpversion' | |
-require_relative 'htmlutils' | |
-require_relative 'httputils' | |
-require_relative 'httpstatus' | |
+require 'webrick/httpversion' | |
+require 'webrick/htmlutils' | |
+require 'webrick/httputils' | |
+require 'webrick/httpstatus' | |
module WEBrick | |
## | |
@@ -51,21 +50,8 @@ | |
attr_accessor :reason_phrase | |
## | |
- # Body may be: | |
- # * a String; | |
- # * an IO-like object that responds to +#read+ and +#readpartial+; | |
- # * a Proc-like object that responds to +#call+. | |
- # | |
- # In the latter case, either #chunked= should be set to +true+, | |
- # or <code>header['content-length']</code> explicitly provided. | |
- # Example: | |
- # | |
- # server.mount_proc '/' do |req, res| | |
- # res.chunked = true | |
- # # or | |
- # # res.header['content-length'] = 10 | |
- # res.body = proc { |out| out.write(Time.now.to_s) } | |
- # end | |
+ # Body may be a String or IO-like object that responds to #read and | |
+ # #readpartial. | |
attr_accessor :body | |
@@ -126,14 +112,13 @@ | |
@chunked = false | |
@filename = nil | |
@sent_size = 0 | |
- @bodytempfile = nil | |
end | |
## | |
# The response's HTTP status line | |
def status_line | |
- "HTTP/#@http_version #@status #@reason_phrase".rstrip << CRLF | |
+ "HTTP/#@http_version #@status #@reason_phrase #{CRLF}" | |
end | |
## | |
@@ -155,7 +140,6 @@ | |
# Sets the response header +field+ to +value+ | |
def []=(field, value) | |
- @chunked = value.to_s.downcase == 'chunked' if field.downcase == 'transfer-encoding' | |
@header[field.downcase] = value.to_s | |
end | |
@@ -268,11 +252,8 @@ | |
elsif %r{^multipart/byteranges} =~ @header['content-type'] | |
@header.delete('content-length') | |
elsif @header['content-length'].nil? | |
- if @body.respond_to? :readpartial | |
- elsif @body.respond_to? :call | |
- make_body_tempfile | |
- else | |
- @header['content-length'] = (@body ? @body.bytesize : 0).to_s | |
+ unless @body.is_a?(IO) | |
+ @header['content-length'] = @body ? @body.bytesize : 0 | |
end | |
end | |
@@ -295,38 +276,11 @@ | |
# Location is a single absoluteURI. | |
if location = @header['location'] | |
if @request_uri | |
- @header['location'] = @request_uri.merge(location).to_s | |
+ @header['location'] = @request_uri.merge(location) | |
end | |
end | |
end | |
- def make_body_tempfile # :nodoc: | |
- return if @bodytempfile | |
- bodytempfile = Tempfile.create("webrick") | |
- if @body.nil? | |
- # nothing | |
- elsif @body.respond_to? :readpartial | |
- IO.copy_stream(@body, bodytempfile) | |
- @body.close | |
- elsif @body.respond_to? :call | |
- @body.call(bodytempfile) | |
- else | |
- bodytempfile.write @body | |
- end | |
- bodytempfile.rewind | |
- @body = @bodytempfile = bodytempfile | |
- @header['content-length'] = bodytempfile.stat.size.to_s | |
- end | |
- | |
- def remove_body_tempfile # :nodoc: | |
- if @bodytempfile | |
- @bodytempfile.close | |
- File.unlink @bodytempfile.path | |
- @bodytempfile = nil | |
- end | |
- end | |
- | |
- | |
## | |
# Sends the headers on +socket+ | |
@@ -363,6 +317,12 @@ | |
end | |
end | |
+ def to_s # :nodoc: | |
+ ret = "" | |
+ send_response(ret) | |
+ ret | |
+ end | |
+ | |
## | |
# Redirects to +url+ with a WEBrick::HTTPStatus::Redirect +status+. | |
# | |
@@ -371,9 +331,8 @@ | |
# res.set_redirect WEBrick::HTTPStatus::TemporaryRedirect | |
def set_redirect(status, url) | |
- url = URI(url).to_s | |
@body = "<HTML><A HREF=\"#{url}\">#{url}</A>.</HTML>\n" | |
- @header['location'] = url | |
+ @header['location'] = url.to_s | |
raise status | |
end | |
@@ -485,7 +444,6 @@ | |
ensure | |
@body.close | |
end | |
- remove_body_tempfile | |
end | |
def send_body_string(socket) | |
@@ -518,12 +476,7 @@ | |
socket.write("0#{CRLF}#{CRLF}") | |
else | |
size = @header['content-length'].to_i | |
- if @bodytempfile | |
- @bodytempfile.rewind | |
- IO.copy_stream(@bodytempfile, socket) | |
- else | |
- @body.call(socket) | |
- end | |
+ @body.call(socket) | |
@sent_size = size | |
end | |
end | |
diff -u lib/webrick/https.rb ../ruby/lib/webrick/https.rb | |
--- lib/webrick/https.rb 2020-06-29 23:36:38.000000000 -0500 | |
+++ ../ruby/lib/webrick/https.rb 2020-06-30 14:34:33.000000000 -0500 | |
@@ -9,8 +9,8 @@ | |
# | |
# $IPR: https.rb,v 1.15 2003/07/22 19:20:42 gotoyuzo Exp $ | |
-require_relative 'ssl' | |
-require_relative 'httpserver' | |
+require 'webrick/ssl' | |
+require 'webrick/httpserver' | |
module WEBrick | |
module Config | |
diff -u lib/webrick/httpserver.rb ../ruby/lib/webrick/httpserver.rb | |
--- lib/webrick/httpserver.rb 2020-06-29 23:36:38.000000000 -0500 | |
+++ ../ruby/lib/webrick/httpserver.rb 2020-06-30 14:34:33.000000000 -0500 | |
@@ -10,13 +10,13 @@ | |
# $IPR: httpserver.rb,v 1.63 2002/10/01 17:16:32 gotoyuzo Exp $ | |
require 'io/wait' | |
-require_relative 'server' | |
-require_relative 'httputils' | |
-require_relative 'httpstatus' | |
-require_relative 'httprequest' | |
-require_relative 'httpresponse' | |
-require_relative 'httpservlet' | |
-require_relative 'accesslog' | |
+require 'webrick/server' | |
+require 'webrick/httputils' | |
+require 'webrick/httpstatus' | |
+require 'webrick/httprequest' | |
+require 'webrick/httpresponse' | |
+require 'webrick/httpservlet' | |
+require 'webrick/accesslog' | |
module WEBrick | |
class HTTPServerError < ServerError; end | |
@@ -68,8 +68,8 @@ | |
def run(sock) | |
while true | |
- req = create_request(@config) | |
- res = create_response(@config) | |
+ res = HTTPResponse.new(@config) | |
+ req = HTTPRequest.new(@config) | |
server = self | |
begin | |
timeout = @config[:RequestTimeout] | |
@@ -225,20 +225,6 @@ | |
end | |
## | |
- # Creates the HTTPRequest used when handling the HTTP | |
- # request. Can be overridden by subclasses. | |
- def create_request(with_webrick_config) | |
- HTTPRequest.new(with_webrick_config) | |
- end | |
- | |
- ## | |
- # Creates the HTTPResponse used when handling the HTTP | |
- # request. Can be overridden by subclasses. | |
- def create_response(with_webrick_config) | |
- HTTPResponse.new(with_webrick_config) | |
- end | |
- | |
- ## | |
# Mount table for the path a servlet is mounted on in the directory space | |
# of the server. Users of WEBrick can only access this indirectly via | |
# WEBrick::HTTPServer#mount, WEBrick::HTTPServer#unmount and | |
Common subdirectories: lib/webrick/httpservlet and ../ruby/lib/webrick/httpservlet | |
diff -u lib/webrick/httpservlet.rb ../ruby/lib/webrick/httpservlet.rb | |
--- lib/webrick/httpservlet.rb 2020-06-29 23:36:38.000000000 -0500 | |
+++ ../ruby/lib/webrick/httpservlet.rb 2020-06-30 14:34:33.000000000 -0500 | |
@@ -9,11 +9,11 @@ | |
# | |
# $IPR: httpservlet.rb,v 1.21 2003/02/23 12:24:46 gotoyuzo Exp $ | |
-require_relative 'httpservlet/abstract' | |
-require_relative 'httpservlet/filehandler' | |
-require_relative 'httpservlet/cgihandler' | |
-require_relative 'httpservlet/erbhandler' | |
-require_relative 'httpservlet/prochandler' | |
+require 'webrick/httpservlet/abstract' | |
+require 'webrick/httpservlet/filehandler' | |
+require 'webrick/httpservlet/cgihandler' | |
+require 'webrick/httpservlet/erbhandler' | |
+require 'webrick/httpservlet/prochandler' | |
module WEBrick | |
module HTTPServlet | |
diff -u lib/webrick/httpstatus.rb ../ruby/lib/webrick/httpstatus.rb | |
--- lib/webrick/httpstatus.rb 2020-06-29 23:36:38.000000000 -0500 | |
+++ ../ruby/lib/webrick/httpstatus.rb 2020-06-30 14:34:33.000000000 -0500 | |
@@ -9,7 +9,7 @@ | |
# | |
# $IPR: httpstatus.rb,v 1.11 2003/03/24 20:18:55 gotoyuzo Exp $ | |
-require_relative 'accesslog' | |
+require 'webrick/accesslog' | |
module WEBrick | |
diff -u lib/webrick/httputils.rb ../ruby/lib/webrick/httputils.rb | |
--- lib/webrick/httputils.rb 2020-06-29 23:37:23.000000000 -0500 | |
+++ ../ruby/lib/webrick/httputils.rb 2020-06-30 14:34:33.000000000 -0500 | |
@@ -95,7 +95,6 @@ | |
"tif" => "image/tiff", | |
"tiff" => "image/tiff", | |
"txt" => "text/plain", | |
- "wasm" => "application/wasm", | |
"xbm" => "image/x-xbitmap", | |
"xhtml" => "text/html", | |
"xls" => "application/vnd.ms-excel", | |
@@ -162,7 +161,10 @@ | |
end | |
} | |
header.each{|key, values| | |
- values.each(&:strip!) | |
+ values.each{|value| | |
+ value.strip! | |
+ value.gsub!(/\s+/, " ") | |
+ } | |
} | |
header | |
end | |
diff -u lib/webrick/server.rb ../ruby/lib/webrick/server.rb | |
--- lib/webrick/server.rb 2020-06-29 23:36:38.000000000 -0500 | |
+++ ../ruby/lib/webrick/server.rb 2020-06-30 14:34:33.000000000 -0500 | |
@@ -10,8 +10,8 @@ | |
# $IPR: server.rb,v 1.62 2003/07/22 19:20:43 gotoyuzo Exp $ | |
require 'socket' | |
-require_relative 'config' | |
-require_relative 'log' | |
+require 'webrick/config' | |
+require 'webrick/log' | |
module WEBrick | |
diff -u lib/webrick/ssl.rb ../ruby/lib/webrick/ssl.rb | |
--- lib/webrick/ssl.rb 2020-06-29 23:36:38.000000000 -0500 | |
+++ ../ruby/lib/webrick/ssl.rb 2020-06-30 14:34:33.000000000 -0500 | |
@@ -130,7 +130,7 @@ | |
aki = ef.create_extension("authorityKeyIdentifier", | |
"keyid:always,issuer:always") | |
cert.add_extension(aki) | |
- cert.sign(rsa, OpenSSL::Digest::SHA256.new) | |
+ cert.sign(rsa, OpenSSL::Digest::SHA1.new) | |
return [ cert, rsa ] | |
end | |
@@ -181,7 +181,7 @@ | |
unless config[:SSLCertificate] | |
cn = config[:SSLCertName] | |
comment = config[:SSLCertComment] | |
- cert, key = Utils::create_self_signed_cert(2048, cn, comment) | |
+ cert, key = Utils::create_self_signed_cert(1024, cn, comment) | |
config[:SSLCertificate] = cert | |
config[:SSLPrivateKey] = key | |
end | |
diff -u lib/webrick/version.rb ../ruby/lib/webrick/version.rb | |
--- lib/webrick/version.rb 2020-06-29 23:37:23.000000000 -0500 | |
+++ ../ruby/lib/webrick/version.rb 2020-06-30 14:34:33.000000000 -0500 | |
@@ -14,5 +14,5 @@ | |
## | |
# The WEBrick version | |
- VERSION = "1.6.0" | |
+ VERSION = "1.4.2" | |
end | |
Only in ../ruby/lib/webrick: webrick.gemspec |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment