[前][次][番号順一覧][スレッド一覧]

ruby-changes:49351

From: naruse <ko1@a...>
Date: Mon, 25 Dec 2017 15:51:20 +0900 (JST)
Subject: [ruby-changes:49351] naruse:r61466: Release branch of Ruby 2.5

naruse	2017-12-25 15:51:11 +0900 (Mon, 25 Dec 2017)

  New Revision: 61466

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61466

  Log:
    Release branch of Ruby 2.5

  Added directories:
    branches/ruby_2_5/
Index: ruby_2_5/lib/webrick/httpservlet/erbhandler.rb
===================================================================
--- ruby_2_5/lib/webrick/httpservlet/erbhandler.rb	(nonexistent)
+++ ruby_2_5/lib/webrick/httpservlet/erbhandler.rb	(revision 61466)
@@ -0,0 +1,88 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_5/lib/webrick/httpservlet/erbhandler.rb#L1
+# frozen_string_literal: false
+#
+# erbhandler.rb -- ERBHandler Class
+#
+# Author: IPR -- Internet Programming with Ruby -- writers
+# Copyright (c) 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
+# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
+# reserved.
+#
+# $IPR: erbhandler.rb,v 1.25 2003/02/24 19:25:31 gotoyuzo Exp $
+
+require 'webrick/httpservlet/abstract.rb'
+
+require 'erb'
+
+module WEBrick
+  module HTTPServlet
+
+    ##
+    # ERBHandler evaluates an ERB file and returns the result.  This handler
+    # is automatically used if there are .rhtml files in a directory served by
+    # the FileHandler.
+    #
+    # ERBHandler supports GET and POST methods.
+    #
+    # The ERB file is evaluated with the local variables +servlet_request+ and
+    # +servlet_response+ which are a WEBrick::HTTPRequest and
+    # WEBrick::HTTPResponse respectively.
+    #
+    # Example .rhtml file:
+    #
+    #   Request to <%= servlet_request.request_uri %>
+    #
+    #   Query params <%= servlet_request.query.inspect %>
+
+    class ERBHandler < AbstractServlet
+
+      ##
+      # Creates a new ERBHandler on +server+ that will evaluate and serve the
+      # ERB file +name+
+
+      def initialize(server, name)
+        super(server, name)
+        @script_filename = name
+      end
+
+      ##
+      # Handles GET requests
+
+      def do_GET(req, res)
+        unless defined?(ERB)
+          @logger.warn "#{self.class}: ERB not defined."
+          raise HTTPStatus::Forbidden, "ERBHandler cannot work."
+        end
+        begin
+          data = File.open(@script_filename, &:read)
+          res.body = evaluate(ERB.new(data), req, res)
+          res['content-type'] ||=
+            HTTPUtils::mime_type(@script_filename, @config[:MimeTypes])
+        rescue StandardError
+          raise
+        rescue Exception => ex
+          @logger.error(ex)
+          raise HTTPStatus::InternalServerError, ex.message
+        end
+      end
+
+      ##
+      # Handles POST requests
+
+      alias do_POST do_GET
+
+      private
+
+      ##
+      # Evaluates +erb+ providing +servlet_request+ and +servlet_response+ as
+      # local variables.
+
+      def evaluate(erb, servlet_request, servlet_response)
+        Module.new.module_eval{
+          servlet_request.meta_vars
+          servlet_request.query
+          erb.result(binding)
+        }
+      end
+    end
+  end
+end

Property changes on: ruby_2_5/lib/webrick/httpservlet/erbhandler.rb
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+LF
\ No newline at end of property
Index: ruby_2_5/lib/webrick/httpservlet/cgihandler.rb
===================================================================
--- ruby_2_5/lib/webrick/httpservlet/cgihandler.rb	(nonexistent)
+++ ruby_2_5/lib/webrick/httpservlet/cgihandler.rb	(revision 61466)
@@ -0,0 +1,122 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_5/lib/webrick/httpservlet/cgihandler.rb#L1
+# frozen_string_literal: false
+#
+# cgihandler.rb -- CGIHandler Class
+#
+# Author: IPR -- Internet Programming with Ruby -- writers
+# Copyright (c) 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
+# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
+# reserved.
+#
+# $IPR: cgihandler.rb,v 1.27 2003/03/21 19:56:01 gotoyuzo Exp $
+
+require 'rbconfig'
+require 'tempfile'
+require 'webrick/config'
+require 'webrick/httpservlet/abstract'
+
+module WEBrick
+  module HTTPServlet
+
+    ##
+    # Servlet for handling CGI scripts
+    #
+    # Example:
+    #
+    #  server.mount('/cgi/my_script', WEBrick::HTTPServlet::CGIHandler,
+    #               '/path/to/my_script')
+
+    class CGIHandler < AbstractServlet
+      Ruby = RbConfig.ruby # :nodoc:
+      CGIRunner = "\"#{Ruby}\" \"#{WEBrick::Config::LIBDIR}/httpservlet/cgi_runner.rb\"" # :nodoc:
+
+      ##
+      # Creates a new CGI script servlet for the script at +name+
+
+      def initialize(server, name)
+        super(server, name)
+        @script_filename = name
+        @tempdir = server[:TempDir]
+        @cgicmd = "#{CGIRunner} #{server[:CGIInterpreter]}"
+      end
+
+      # :stopdoc:
+
+      def do_GET(req, res)
+        cgi_in = IO::popen(@cgicmd, "wb")
+        cgi_out = Tempfile.new("webrick.cgiout.", @tempdir, mode: IO::BINARY)
+        cgi_out.set_encoding("ASCII-8BIT")
+        cgi_err = Tempfile.new("webrick.cgierr.", @tempdir, mode: IO::BINARY)
+        cgi_err.set_encoding("ASCII-8BIT")
+        begin
+          cgi_in.sync = true
+          meta = req.meta_vars
+          meta["SCRIPT_FILENAME"] = @script_filename
+          meta["PATH"] = @config[:CGIPathEnv]
+          meta.delete("HTTP_PROXY")
+          if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM
+            meta["SystemRoot"] = ENV["SystemRoot"]
+          end
+          dump = Marshal.dump(meta)
+
+          cgi_in.write("%8d" % cgi_out.path.bytesize)
+          cgi_in.write(cgi_out.path)
+          cgi_in.write("%8d" % cgi_err.path.bytesize)
+          cgi_in.write(cgi_err.path)
+          cgi_in.write("%8d" % dump.bytesize)
+          cgi_in.write(dump)
+
+          if req.body and req.body.bytesize > 0
+            cgi_in.write(req.body)
+          end
+        ensure
+          cgi_in.close
+          status = $?.exitstatus
+          sleep 0.1 if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM
+          data = cgi_out.read
+          cgi_out.close(true)
+          if errmsg = cgi_err.read
+            if errmsg.bytesize > 0
+              @logger.error("CGIHandler: #{@script_filename}:\n" + errmsg)
+            end
+          end
+          cgi_err.close(true)
+        end
+
+        if status != 0
+          @logger.error("CGIHandler: #{@script_filename} exit with #{status}")
+        end
+
+        data = "" unless data
+        raw_header, body = data.split(/^[\xd\xa]+/, 2)
+        raise HTTPStatus::InternalServerError,
+          "Premature end of script headers: #{@script_filename}" if body.nil?
+
+        begin
+          header = HTTPUtils::parse_header(raw_header)
+          if /^(\d+)/ =~ header['status'][0]
+            res.status = $1.to_i
+            header.delete('status')
+          end
+          if header.has_key?('location')
+            # RFC 3875 6.2.3, 6.2.4
+            res.status = 302 unless (300...400) === res.status
+          end
+          if header.has_key?('set-cookie')
+            header['set-cookie'].each{|k|
+              res.cookies << Cookie.parse_set_cookie(k)
+            }
+            header.delete('set-cookie')
+          end
+          header.each{|key, val| res[key] = val.join(", ") }
+        rescue => ex
+          raise HTTPStatus::InternalServerError, ex.message
+        end
+        res.body = body
+      end
+      alias do_POST do_GET
+
+      # :startdoc:
+    end
+
+  end
+end

Property changes on: ruby_2_5/lib/webrick/httpservlet/cgihandler.rb
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+LF
\ No newline at end of property
Index: ruby_2_5/lib/webrick/httpstatus.rb
===================================================================
--- ruby_2_5/lib/webrick/httpstatus.rb	(nonexistent)
+++ ruby_2_5/lib/webrick/httpstatus.rb	(revision 61466)
@@ -0,0 +1,194 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_5/lib/webrick/httpstatus.rb#L1
+# frozen_string_literal: false
+#--
+# httpstatus.rb -- HTTPStatus Class
+#
+# Author: IPR -- Internet Programming with Ruby -- writers
+# Copyright (c) 2000, 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
+# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
+# reserved.
+#
+# $IPR: httpstatus.rb,v 1.11 2003/03/24 20:18:55 gotoyuzo Exp $
+
+require 'webrick/accesslog'
+
+module WEBrick
+
+  ##
+  # This module is used to manager HTTP status codes.
+  #
+  # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for more
+  # information.
+  module HTTPStatus
+
+    ##
+    # Root of the HTTP status class hierarchy
+    class Status < StandardError
+      class << self
+        attr_reader :code, :reason_phrase # :nodoc:
+      end
+
+      # Returns the HTTP status code
+      def code() self::class::code end
+
+      # Returns the HTTP status description
+      def reason_phrase() self::class::reason_phrase end
+
+      alias to_i code # :nodoc:
+    end
+
+    # Root of the HTTP info statuses
+    class Info        < Status; end
+    # Root of the HTTP success statuses
+    class Success     < Status; end
+    # Root of the HTTP redirect statuses
+    class Redirect    < Status; end
+    # Root of the HTTP error statuses
+    class Error       < Status; end
+    # Root of the HTTP client error statuses
+    class ClientError < Error; end
+    # Root of the HTTP server error statuses
+    class ServerError < Error; end
+
+    class EOFError < StandardError; end
+
+    # HTTP status codes and descriptions
+    StatusMessage = { # :nodoc:
+      100 => 'Continue',
+      101 => 'Switching Protocols',
+      200 => 'OK',
+      201 => 'Created',
+      202 => 'Accepted',
+      203 => 'Non-Authoritative Information',
+      204 => 'No Content',
+      205 => 'Reset Content',
+      206 => 'Partial Content',
+      207 => 'Multi-Status',
+      300 => 'Multiple Choices',
+      301 => 'Moved Permanently',
+      302 => 'Found',
+      303 => 'See Other',
+      304 => 'Not Modified',
+      305 => 'Use Proxy',
+      307 => 'Temporary Redirect',
+      400 => 'Bad Request',
+      401 => 'Unauthorized',
+      402 => 'Payment Required',
+      403 => 'Forbidden',
+      404 => 'Not Found',
+      405 => 'Method Not Allowed',
+      406 => 'Not Acceptable',
+      407 => 'Proxy Authentication Required',
+      408 => 'Request Timeout',
+      409 => 'Conflict',
+      410 => 'Gone',
+      411 => 'Length Required',
+      412 => 'Precondition Failed',
+      413 => 'Request Entity Too Large',
+      414 => 'Request-URI Too Large',
+      415 => 'Unsupported Media Type',
+      416 => 'Request Range Not Satisfiable',
+      417 => 'Expectation Failed',
+      422 => 'Unprocessable Entity',
+      423 => 'Locked',
+      424 => 'Failed Dependency',
+      426 => 'Upgrade Required',
+      428 => 'Precondition Required',
+      429 => 'Too Many Requests',
+      431 => 'Request Header Fields Too Large',
+      451 => 'Unavailable For Legal Reasons',
+      500 => 'Internal Server Error',
+      501 => 'Not Implemented',
+      502 => 'Bad Gateway',
+      503 => 'Service Unavailable',
+      504 => 'Gateway Timeout',
+      505 => 'HTTP Version Not Supported',
+      507 => 'Insufficient Storage',
+      511 => 'Network Authentication Required',
+    }
+
+    # Maps a status code to the corresponding Status class
+    CodeToError = {} # :nodoc:
+
+    # Creates a status or error class for each status code and
+    # populates the CodeToError map.
+    StatusMessage.each{|code, message|
+      message.freeze
+      var_name = message.gsub(/[ \-]/,'_').upcase
+      err_name = message.gsub(/[ \-]/,'')
+
+      case code
+      when 100...200; parent = Info
+      when 200...300; parent = Success
+      when 300...400; parent = Redirect
+      when 400...500; parent = ClientError
+      when 500...600; parent = ServerError
+      end
+
+      const_set("RC_#{var_name}", code)
+      err_class = Class.new(parent)
+      err_class.instance_variable_set(:@code, code)
+      err_class.instance_variable_set(:@reason_phrase, message)
+      const_set(err_name, err_class)
+      CodeToError[code] = err_class
+    }
+
+    ##
+    # Returns the description corresponding to the HTTP status +code+
+    #
+    #   WEBrick::HTTPStatus.reason_phrase 404
+    #   => "Not Found"
+    def reason_phrase(code)
+      StatusMessage[code.to_i]
+    end
+
+    ##
+    # Is +code+ an informational status?
+    def info?(code)
+      code.to_i >= 100 and code.to_i < 200
+    end
+
+    ##
+    # Is +code+ a successful status?
+    def success?(code)
+      code.to_i >= 200 and code.to_i < 300
+    end
+
+    ##
+    # Is +code+ a redirection status?
+    def redirect?(code)
+      code.to_i >= 300 and code.to_i < 400
+    end
+
+    ##
+    # Is +code+ an error status?
+    def error?(code)
+      code.to_i >= 400 and code.to_i < 600
+    end
+
+    ##
+    # Is +code+ a client error status?
+    def client_error?(code)
+      code.to_i >= 400 and code.to_i < 500
+    end
+
+    ##
+    # Is +code+ a server error status?
+    def server_error?(code)
+      code.to_i >= 500 and code.to_i < 600
+    end
+
+    ##
+    # Returns the status class corresponding to +code+
+    #
+    #   WEBrick::HTTPStatus[302]
+    #   => WEBrick::HTTPStatus::NotFound
+    #
+    def self.[](code)
+      CodeToError[code]
+    end
+
+    module_function :reason_phrase
+    module_function :info?, :success?, :redirect?, :error?
+    module_function :client_error?, :server_error?
+  end
+end

Property changes on: ruby_2_5/lib/webrick/httpstatus.rb
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+LF
\ No newline at end of property
Index: ruby_2_5/lib/webrick/httpversion.rb
===================================================================
--- ruby_2_5/lib/webrick/httpversion.rb	(nonexistent)
+++ ruby_2_5/lib/webrick/httpversion.rb	(revision 61466)
@@ -0,0 +1,76 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_5/lib/webrick/httpversion.rb#L1
+# frozen_string_literal: false
+#--
+# HTTPVersion.rb -- presentation of HTTP version
+#
+# Author: IPR -- Internet Programming with Ruby -- writers
+# Copyright (c) 2002 Internet Programming with Ruby writers. All rights
+# reserved.
+#
+# $IPR: httpversion.rb,v 1.5 2002/09/21 12:23:37 gotoyuzo Exp $
+
+module WEBrick
+
+  ##
+  # Represents an HTTP protocol version
+
+  class HTTPVersion
+    include Comparable
+
+    ##
+    # The major protocol version number
+
+    attr_accessor :major
+
+    ##
+    # The minor protocol version number
+
+    attr_accessor :minor
+
+    ##
+    # Converts +version+ into an HTTPVersion
+
+    def self.convert(version)
+      version.is_a?(self) ? version : new(version)
+    end
+
+    ##
+    # Creates a new HTTPVersion from +version+.
+
+    def initialize(version)
+      case version
+      when HTTPVersion
+        @major, @minor = version.major, version.minor
+      when String
+        if /^(\d+)\.(\d+)$/ =~ version
+          @major, @minor = $1.to_i, $2.to_i
+        end
+      end
+      if @major.nil? || @minor.nil?
+        raise ArgumentError,
+          format("cannot convert %s into %s", version.class, self.class)
+      end
+    end
+
+    ##
+    # Compares this version with +other+ according to the HTTP specification
+    # rules.
+
+    def <=>(other)
+      unless other.is_a?(self.class)
+        other = self.class.new(other)
+      end
+      if (ret = @major <=> other.major) == 0
+        return @minor <=> other.minor
+      end
+      return ret
+    end
+
+    ##
+    # The HTTP version as show in the HTTP request and response.  For example,
+    # "1.1"
+
+    def to_s
+      format("%d.%d", @major, @minor)
+    end
+  end
+end

Property changes on: ruby_2_5/lib/webrick/httpversion.rb
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+LF
\ No newline at end of property
Index: ruby_2_5/lib/webrick/accesslog.rb
===================================================================
--- ruby_2_5/lib/webrick/accesslog.rb	(nonexistent)
+++ ruby_2_5/lib/webrick/accesslog.rb	(revision 61466)
@@ -0,0 +1,159 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_5/lib/webrick/accesslog.rb#L1
+# frozen_string_literal: false
+#--
+# accesslog.rb -- Access log handling utilities
+#
+# Author: IPR -- Internet Programming with Ruby -- writers
+# Copyright (c) 2002 keita yamaguchi
+# Copyright (c) 2002 Internet Programming with Ruby writers
+#
+# $IPR: accesslog.rb,v 1.1 2002/10/01 17:16:32 gotoyuzo Exp $
+
+module WEBrick
+
+  ##
+  # AccessLog provides logging to various files in various formats.
+  #
+  # Multiple logs may be written to at the same time:
+  #
+  #   access_log = [
+  #     [$stderr, WEBrick::AccessLog::COMMON_LOG_FORMAT],
+  #     [$stderr, WEBrick::AccessLog::REFERER_LOG_FORMAT],
+  #   ]
+  #
+  #   server = WEBrick::HTTPServer.new :AccessLog => access_log
+  #
+  # Custom log formats may be defined.  WEBrick::AccessLog provides a subset
+  # of the formatting from Apache's mod_log_config
+  # http://httpd.apache.org/docs/mod/mod_log_config.html#formats.  See
+  # AccessLog::setup_params for a list of supported options
+
+  module AccessLog
+
+    ##
+    # Raised if a parameter such as %e, %i, %o or %n is used without fetching
+    # a specific field.
+
+    class AccessLogError < StandardError; end
+
+    ##
+    # The Common Log Format's time format
+
+    CLF_TIME_FORMAT     = "[%d/%b/%Y:%H:%M:%S %Z]"
+
+    ##
+    # Common Log Format
+
+    COMMON_LOG_FORMAT   = "%h %l %u %t \"%r\" %s %b"
+
+    ##
+    # Short alias for Common Log Format
+
+    CLF                 = COMMON_LOG_FORMAT
+
+    ##
+    # Referer Log Format
+
+    REFERER_LOG_FORMAT  = "%{Referer}i -> %U"
+
+    ##
+    # User-Agent Log Format
+
+    AGENT_LOG_FORMAT    = "%{User-Agent}i"
+
+    ##
+    # Combined Log Format
+
+    COMBINED_LOG_FORMAT = "#{CLF} \"%{Referer}i\" \"%{User-agent}i\""
+
+    module_function
+
+    # This format specification is a subset of mod_log_config of Apache:
+    #
+    # %a:: Remote IP address
+    # %b:: Total response size
+    # %e{variable}:: Given variable in ENV
+    # %f:: Response filename
+    # %h:: Remote host name
+    # %{header}i:: Given request header
+    # %l:: Remote logname, always "-"
+    # %m:: Request method
+    # %{attr}n:: Given request attribute from <tt>req.attributes</tt>
+    # %{header}o:: Given response header
+    # %p:: Server's request port
+    # %{format}p:: The canonical port of the server serving the request or the
+    #              actual port or the client's actual port.  Valid formats are
+    #              canonical, local or remote.
+    # %q:: Request query string
+    # %r:: First line of the request
+    # %s:: Request status
+    # %t:: Time the request was received
+    # %T:: Time taken to process the request
+    # %u:: Remote user from auth
+    # %U:: Unparsed URI
+    # %%:: Literal %
+
+    def setup_params(config, req, res)
+      params = Hash.new("")
+      params["a"] = req.peeraddr[3]
+      params["b"] = res.sent_size
+      params["e"] = ENV
+      params["f"] = res.filename || ""
+      params["h"] = req.peeraddr[2]
+      params["i"] = req
+      params["l"] = "-"
+      params["m"] = req.request_method
+      params["n"] = req.attributes
+      params["o"] = res
+      params["p"] = req.port
+      params["q"] = req.query_string
+      params["r"] = req.request_line.sub(/\x0d?\x0a\z/o, '')
+      params["s"] = res.status       # won't support "%>s"
+      params["t"] = req.request_time
+      params["T"] = Time.now - req.request_time
+      params["u"] = req.user || "-"
+      params["U"] = req.unparsed_uri
+      params["v"] = config[:ServerName]
+      params
+    end
+
+    ##
+    # Formats +params+ according to +format_string+ which is described in
+    # setup_params.
+
+    def format(format_string, params)
+      format_string.gsub(/\%(?:\{(.*?)\})?>?([a-zA-Z%])/){
+         param, spec = $1, $2
+         case spec[0]
+         when ?e, ?i, ?n, ?o
+           raise AccessLogError,
+             "parameter is required for \"#{spec}\"" unless param
+           (param = params[spec][param]) ? escape( (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]