rubysl-webrick 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE +25 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/rubysl/webrick.rb +2 -0
- data/lib/rubysl/webrick/version.rb +5 -0
- data/lib/rubysl/webrick/webrick.rb +29 -0
- data/lib/webrick.rb +1 -0
- data/lib/webrick/accesslog.rb +67 -0
- data/lib/webrick/cgi.rb +257 -0
- data/lib/webrick/compat.rb +15 -0
- data/lib/webrick/config.rb +97 -0
- data/lib/webrick/cookie.rb +110 -0
- data/lib/webrick/htmlutils.rb +25 -0
- data/lib/webrick/httpauth.rb +45 -0
- data/lib/webrick/httpauth/authenticator.rb +79 -0
- data/lib/webrick/httpauth/basicauth.rb +65 -0
- data/lib/webrick/httpauth/digestauth.rb +343 -0
- data/lib/webrick/httpauth/htdigest.rb +91 -0
- data/lib/webrick/httpauth/htgroup.rb +61 -0
- data/lib/webrick/httpauth/htpasswd.rb +83 -0
- data/lib/webrick/httpauth/userdb.rb +29 -0
- data/lib/webrick/httpproxy.rb +254 -0
- data/lib/webrick/httprequest.rb +365 -0
- data/lib/webrick/httpresponse.rb +327 -0
- data/lib/webrick/https.rb +63 -0
- data/lib/webrick/httpserver.rb +210 -0
- data/lib/webrick/httpservlet.rb +22 -0
- data/lib/webrick/httpservlet/abstract.rb +71 -0
- data/lib/webrick/httpservlet/cgi_runner.rb +45 -0
- data/lib/webrick/httpservlet/cgihandler.rb +104 -0
- data/lib/webrick/httpservlet/erbhandler.rb +54 -0
- data/lib/webrick/httpservlet/filehandler.rb +398 -0
- data/lib/webrick/httpservlet/prochandler.rb +33 -0
- data/lib/webrick/httpstatus.rb +126 -0
- data/lib/webrick/httputils.rb +391 -0
- data/lib/webrick/httpversion.rb +49 -0
- data/lib/webrick/log.rb +88 -0
- data/lib/webrick/server.rb +200 -0
- data/lib/webrick/ssl.rb +126 -0
- data/lib/webrick/utils.rb +100 -0
- data/lib/webrick/version.rb +13 -0
- data/rubysl-webrick.gemspec +23 -0
- metadata +145 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: d8994245d4c318c3596b0c96a9608c372d0fd7fd
         | 
| 4 | 
            +
              data.tar.gz: 4741b54181f8e4ace05485f7985d1fcc3e3fd28e
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 9f294bfa3fe38668ae4bc1d5a82ddde945038cb1823e3f1f7dceb6ceb16c5afc8bdc74dcfa63d2fea181dc2c51e38de468c85e676187380dc3f472f0ae900158
         | 
| 7 | 
            +
              data.tar.gz: 747dcf8e42c579a4cf766167e5b56a7d58160277b0f48a889c40f82d175ecae054ed83275d8870a01d956c95f3574865924bf85923511f958b19243e36928019
         | 
    
        data/.gitignore
    ADDED
    
    
    
        data/.travis.yml
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/LICENSE
    ADDED
    
    | @@ -0,0 +1,25 @@ | |
| 1 | 
            +
            Copyright (c) 2013, Brian Shirai
         | 
| 2 | 
            +
            All rights reserved.
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            Redistribution and use in source and binary forms, with or without
         | 
| 5 | 
            +
            modification, are permitted provided that the following conditions are met:
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            1. Redistributions of source code must retain the above copyright notice, this
         | 
| 8 | 
            +
               list of conditions and the following disclaimer.
         | 
| 9 | 
            +
            2. Redistributions in binary form must reproduce the above copyright notice,
         | 
| 10 | 
            +
               this list of conditions and the following disclaimer in the documentation
         | 
| 11 | 
            +
               and/or other materials provided with the distribution.
         | 
| 12 | 
            +
            3. Neither the name of the library nor the names of its contributors may be
         | 
| 13 | 
            +
               used to endorse or promote products derived from this software without
         | 
| 14 | 
            +
               specific prior written permission.
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
         | 
| 17 | 
            +
            AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
         | 
| 18 | 
            +
            IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
         | 
| 19 | 
            +
            DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT,
         | 
| 20 | 
            +
            INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
         | 
| 21 | 
            +
            BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
         | 
| 22 | 
            +
            DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
         | 
| 23 | 
            +
            OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
         | 
| 24 | 
            +
            NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
         | 
| 25 | 
            +
            EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            # Rubysl::Webrick
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            TODO: Write a gem description
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ## Installation
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            Add this line to your application's Gemfile:
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                gem 'rubysl-webrick'
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            And then execute:
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                $ bundle
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            Or install it yourself as:
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                $ gem install rubysl-webrick
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            ## Usage
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            TODO: Write usage instructions here
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            ## Contributing
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            1. Fork it
         | 
| 26 | 
            +
            2. Create your feature branch (`git checkout -b my-new-feature`)
         | 
| 27 | 
            +
            3. Commit your changes (`git commit -am 'Add some feature'`)
         | 
| 28 | 
            +
            4. Push to the branch (`git push origin my-new-feature`)
         | 
| 29 | 
            +
            5. Create new Pull Request
         | 
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            require "bundler/gem_tasks"
         | 
| @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            #
         | 
| 2 | 
            +
            # WEBrick -- WEB server toolkit.
         | 
| 3 | 
            +
            #
         | 
| 4 | 
            +
            # Author: IPR -- Internet Programming with Ruby -- writers
         | 
| 5 | 
            +
            # Copyright (c) 2000 TAKAHASHI Masayoshi, GOTOU YUUZOU
         | 
| 6 | 
            +
            # Copyright (c) 2002 Internet Programming with Ruby writers. All rights
         | 
| 7 | 
            +
            # reserved.
         | 
| 8 | 
            +
            #
         | 
| 9 | 
            +
            # $IPR: webrick.rb,v 1.12 2002/10/01 17:16:31 gotoyuzo Exp $
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            require 'webrick/compat.rb'
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            require 'webrick/version.rb'
         | 
| 14 | 
            +
            require 'webrick/config.rb'
         | 
| 15 | 
            +
            require 'webrick/log.rb'
         | 
| 16 | 
            +
            require 'webrick/server.rb'
         | 
| 17 | 
            +
            require 'webrick/utils.rb'
         | 
| 18 | 
            +
            require 'webrick/accesslog'
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            require 'webrick/htmlutils.rb'
         | 
| 21 | 
            +
            require 'webrick/httputils.rb'
         | 
| 22 | 
            +
            require 'webrick/cookie.rb'
         | 
| 23 | 
            +
            require 'webrick/httpversion.rb'
         | 
| 24 | 
            +
            require 'webrick/httpstatus.rb'
         | 
| 25 | 
            +
            require 'webrick/httprequest.rb'
         | 
| 26 | 
            +
            require 'webrick/httpresponse.rb'
         | 
| 27 | 
            +
            require 'webrick/httpserver.rb'
         | 
| 28 | 
            +
            require 'webrick/httpservlet.rb'
         | 
| 29 | 
            +
            require 'webrick/httpauth.rb'
         | 
    
        data/lib/webrick.rb
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            require "rubysl/webrick"
         | 
| @@ -0,0 +1,67 @@ | |
| 1 | 
            +
            #
         | 
| 2 | 
            +
            # accesslog.rb -- Access log handling utilities
         | 
| 3 | 
            +
            #
         | 
| 4 | 
            +
            # Author: IPR -- Internet Programming with Ruby -- writers
         | 
| 5 | 
            +
            # Copyright (c) 2002 keita yamaguchi
         | 
| 6 | 
            +
            # Copyright (c) 2002 Internet Programming with Ruby writers
         | 
| 7 | 
            +
            #
         | 
| 8 | 
            +
            # $IPR: accesslog.rb,v 1.1 2002/10/01 17:16:32 gotoyuzo Exp $
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            module WEBrick
         | 
| 11 | 
            +
              module AccessLog
         | 
| 12 | 
            +
                class AccessLogError < StandardError; end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                CLF_TIME_FORMAT     = "[%d/%b/%Y:%H:%M:%S %Z]"
         | 
| 15 | 
            +
                COMMON_LOG_FORMAT   = "%h %l %u %t \"%r\" %s %b"
         | 
| 16 | 
            +
                CLF                 = COMMON_LOG_FORMAT
         | 
| 17 | 
            +
                REFERER_LOG_FORMAT  = "%{Referer}i -> %U"
         | 
| 18 | 
            +
                AGENT_LOG_FORMAT    = "%{User-Agent}i"
         | 
| 19 | 
            +
                COMBINED_LOG_FORMAT = "#{CLF} \"%{Referer}i\" \"%{User-agent}i\""
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                module_function
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                # This format specification is a subset of mod_log_config of Apache.
         | 
| 24 | 
            +
                #   http://httpd.apache.org/docs/mod/mod_log_config.html#formats
         | 
| 25 | 
            +
                def setup_params(config, req, res)
         | 
| 26 | 
            +
                  params = Hash.new("")
         | 
| 27 | 
            +
                  params["a"] = req.peeraddr[3]
         | 
| 28 | 
            +
                  params["b"] = res.sent_size
         | 
| 29 | 
            +
                  params["e"] = ENV
         | 
| 30 | 
            +
                  params["f"] = res.filename || ""
         | 
| 31 | 
            +
                  params["h"] = req.peeraddr[2]
         | 
| 32 | 
            +
                  params["i"] = req
         | 
| 33 | 
            +
                  params["l"] = "-"
         | 
| 34 | 
            +
                  params["m"] = req.request_method
         | 
| 35 | 
            +
                  params["n"] = req.attributes
         | 
| 36 | 
            +
                  params["o"] = res
         | 
| 37 | 
            +
                  params["p"] = req.port
         | 
| 38 | 
            +
                  params["q"] = req.query_string
         | 
| 39 | 
            +
                  params["r"] = req.request_line.sub(/\x0d?\x0a\z/o, '')
         | 
| 40 | 
            +
                  params["s"] = res.status       # won't support "%>s"
         | 
| 41 | 
            +
                  params["t"] = req.request_time
         | 
| 42 | 
            +
                  params["T"] = Time.now - req.request_time
         | 
| 43 | 
            +
                  params["u"] = req.user || "-"
         | 
| 44 | 
            +
                  params["U"] = req.unparsed_uri
         | 
| 45 | 
            +
                  params["v"] = config[:ServerName]
         | 
| 46 | 
            +
                  params
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                def format(format_string, params)
         | 
| 50 | 
            +
                  format_string.gsub(/\%(?:\{(.*?)\})?>?([a-zA-Z%])/){
         | 
| 51 | 
            +
                     param, spec = $1, $2
         | 
| 52 | 
            +
                     case spec[0]
         | 
| 53 | 
            +
                     when ?e, ?i, ?n, ?o
         | 
| 54 | 
            +
                       raise AccessLogError,
         | 
| 55 | 
            +
                         "parameter is required for \"#{spec}\"" unless param
         | 
| 56 | 
            +
                       params[spec][param] || "-"
         | 
| 57 | 
            +
                     when ?t
         | 
| 58 | 
            +
                       params[spec].strftime(param || CLF_TIME_FORMAT)
         | 
| 59 | 
            +
                     when ?%
         | 
| 60 | 
            +
                       "%"
         | 
| 61 | 
            +
                     else
         | 
| 62 | 
            +
                       params[spec]
         | 
| 63 | 
            +
                     end
         | 
| 64 | 
            +
                  }
         | 
| 65 | 
            +
                end
         | 
| 66 | 
            +
              end
         | 
| 67 | 
            +
            end
         | 
    
        data/lib/webrick/cgi.rb
    ADDED
    
    | @@ -0,0 +1,257 @@ | |
| 1 | 
            +
            #
         | 
| 2 | 
            +
            # cgi.rb -- Yet another CGI library
         | 
| 3 | 
            +
            #
         | 
| 4 | 
            +
            # Author: IPR -- Internet Programming with Ruby -- writers
         | 
| 5 | 
            +
            # Copyright (c) 2003 Internet Programming with Ruby writers. All rights
         | 
| 6 | 
            +
            # reserved.
         | 
| 7 | 
            +
            #
         | 
| 8 | 
            +
            # $Id: cgi.rb 11708 2007-02-12 23:01:19Z shyouhei $
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            require "webrick/httprequest"
         | 
| 11 | 
            +
            require "webrick/httpresponse"
         | 
| 12 | 
            +
            require "webrick/config"
         | 
| 13 | 
            +
            require "stringio"
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            module WEBrick
         | 
| 16 | 
            +
              class CGI
         | 
| 17 | 
            +
                CGIError = Class.new(StandardError)
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                attr_reader :config, :logger
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def initialize(*args)
         | 
| 22 | 
            +
                  if defined?(MOD_RUBY)
         | 
| 23 | 
            +
                    unless ENV.has_key?("GATEWAY_INTERFACE")
         | 
| 24 | 
            +
                      Apache.request.setup_cgi_env
         | 
| 25 | 
            +
                    end
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
                  if %r{HTTP/(\d+\.\d+)} =~ ENV["SERVER_PROTOCOL"]
         | 
| 28 | 
            +
                    httpv = $1
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
                  @config = WEBrick::Config::HTTP.dup.update(
         | 
| 31 | 
            +
                    :ServerSoftware => ENV["SERVER_SOFTWARE"] || "null",
         | 
| 32 | 
            +
                    :HTTPVersion    => HTTPVersion.new(httpv || "1.0"),
         | 
| 33 | 
            +
                    :RunOnCGI       => true,   # to detect if it runs on CGI.
         | 
| 34 | 
            +
                    :NPH            => false   # set true to run as NPH script.
         | 
| 35 | 
            +
                  )
         | 
| 36 | 
            +
                  if config = args.shift
         | 
| 37 | 
            +
                    @config.update(config)
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
                  @config[:Logger] ||= WEBrick::BasicLog.new($stderr)
         | 
| 40 | 
            +
                  @logger = @config[:Logger]
         | 
| 41 | 
            +
                  @options = args
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                def [](key)
         | 
| 45 | 
            +
                  @config[key]
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                def start(env=ENV, stdin=$stdin, stdout=$stdout)
         | 
| 49 | 
            +
                  sock = WEBrick::CGI::Socket.new(@config, env, stdin, stdout)
         | 
| 50 | 
            +
                  req = HTTPRequest.new(@config)
         | 
| 51 | 
            +
                  res = HTTPResponse.new(@config)
         | 
| 52 | 
            +
                  unless @config[:NPH] or defined?(MOD_RUBY)
         | 
| 53 | 
            +
                    def res.setup_header
         | 
| 54 | 
            +
                      unless @header["status"]
         | 
| 55 | 
            +
                        phrase = HTTPStatus::reason_phrase(@status)
         | 
| 56 | 
            +
                        @header["status"] = "#{@status} #{phrase}"
         | 
| 57 | 
            +
                      end
         | 
| 58 | 
            +
                      super
         | 
| 59 | 
            +
                    end
         | 
| 60 | 
            +
                    def res.status_line
         | 
| 61 | 
            +
                      ""
         | 
| 62 | 
            +
                    end
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                  begin
         | 
| 66 | 
            +
                    req.parse(sock)
         | 
| 67 | 
            +
                    req.script_name = (env["SCRIPT_NAME"] || File.expand_path($0)).dup
         | 
| 68 | 
            +
                    req.path_info = (env["PATH_INFO"] || "").dup
         | 
| 69 | 
            +
                    req.query_string = env["QUERY_STRING"]
         | 
| 70 | 
            +
                    req.user = env["REMOTE_USER"]
         | 
| 71 | 
            +
                    res.request_method = req.request_method
         | 
| 72 | 
            +
                    res.request_uri = req.request_uri
         | 
| 73 | 
            +
                    res.request_http_version = req.http_version
         | 
| 74 | 
            +
                    res.keep_alive = req.keep_alive?
         | 
| 75 | 
            +
                    self.service(req, res)
         | 
| 76 | 
            +
                  rescue HTTPStatus::Error => ex
         | 
| 77 | 
            +
                    res.set_error(ex)
         | 
| 78 | 
            +
                  rescue HTTPStatus::Status => ex
         | 
| 79 | 
            +
                    res.status = ex.code
         | 
| 80 | 
            +
                  rescue Exception => ex 
         | 
| 81 | 
            +
                    @logger.error(ex)
         | 
| 82 | 
            +
                    res.set_error(ex, true)
         | 
| 83 | 
            +
                  ensure
         | 
| 84 | 
            +
                    req.fixup
         | 
| 85 | 
            +
                    if defined?(MOD_RUBY)
         | 
| 86 | 
            +
                      res.setup_header
         | 
| 87 | 
            +
                      Apache.request.status_line = "#{res.status} #{res.reason_phrase}"
         | 
| 88 | 
            +
                      Apache.request.status = res.status
         | 
| 89 | 
            +
                      table = Apache.request.headers_out
         | 
| 90 | 
            +
                      res.header.each{|key, val|
         | 
| 91 | 
            +
                        case key
         | 
| 92 | 
            +
                        when /^content-encoding$/i
         | 
| 93 | 
            +
                          Apache::request.content_encoding = val
         | 
| 94 | 
            +
                        when /^content-type$/i
         | 
| 95 | 
            +
                          Apache::request.content_type = val
         | 
| 96 | 
            +
                        else
         | 
| 97 | 
            +
                          table[key] = val.to_s
         | 
| 98 | 
            +
                        end
         | 
| 99 | 
            +
                      }
         | 
| 100 | 
            +
                      res.cookies.each{|cookie|
         | 
| 101 | 
            +
                        table.add("Set-Cookie", cookie.to_s)
         | 
| 102 | 
            +
                      }
         | 
| 103 | 
            +
                      Apache.request.send_http_header
         | 
| 104 | 
            +
                      res.send_body(sock)
         | 
| 105 | 
            +
                    else
         | 
| 106 | 
            +
                      res.send_response(sock)
         | 
| 107 | 
            +
                    end
         | 
| 108 | 
            +
                  end
         | 
| 109 | 
            +
                end
         | 
| 110 | 
            +
             | 
| 111 | 
            +
                def service(req, res)
         | 
| 112 | 
            +
                  method_name = "do_" + req.request_method.gsub(/-/, "_")
         | 
| 113 | 
            +
                  if respond_to?(method_name)
         | 
| 114 | 
            +
                    __send__(method_name, req, res)
         | 
| 115 | 
            +
                  else
         | 
| 116 | 
            +
                    raise HTTPStatus::MethodNotAllowed,
         | 
| 117 | 
            +
                          "unsupported method `#{req.request_method}'."
         | 
| 118 | 
            +
                  end
         | 
| 119 | 
            +
                end
         | 
| 120 | 
            +
             | 
| 121 | 
            +
                class Socket
         | 
| 122 | 
            +
                  include Enumerable
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                  private
         | 
| 125 | 
            +
              
         | 
| 126 | 
            +
                  def initialize(config, env, stdin, stdout)
         | 
| 127 | 
            +
                    @config = config
         | 
| 128 | 
            +
                    @env = env
         | 
| 129 | 
            +
                    @header_part = StringIO.new
         | 
| 130 | 
            +
                    @body_part = stdin
         | 
| 131 | 
            +
                    @out_port = stdout
         | 
| 132 | 
            +
                    @out_port.binmode
         | 
| 133 | 
            +
              
         | 
| 134 | 
            +
                    @server_addr = @env["SERVER_ADDR"] || "0.0.0.0"
         | 
| 135 | 
            +
                    @server_name = @env["SERVER_NAME"]
         | 
| 136 | 
            +
                    @server_port = @env["SERVER_PORT"]
         | 
| 137 | 
            +
                    @remote_addr = @env["REMOTE_ADDR"]
         | 
| 138 | 
            +
                    @remote_host = @env["REMOTE_HOST"] || @remote_addr
         | 
| 139 | 
            +
                    @remote_port = @env["REMOTE_PORT"] || 0
         | 
| 140 | 
            +
             | 
| 141 | 
            +
                    begin
         | 
| 142 | 
            +
                      @header_part << request_line << CRLF
         | 
| 143 | 
            +
                      setup_header
         | 
| 144 | 
            +
                      @header_part << CRLF
         | 
| 145 | 
            +
                      @header_part.rewind
         | 
| 146 | 
            +
                    rescue Exception => ex
         | 
| 147 | 
            +
                      raise CGIError, "invalid CGI environment"
         | 
| 148 | 
            +
                    end
         | 
| 149 | 
            +
                  end
         | 
| 150 | 
            +
             | 
| 151 | 
            +
                  def request_line
         | 
| 152 | 
            +
                    meth = @env["REQUEST_METHOD"] || "GET"
         | 
| 153 | 
            +
                    unless url = @env["REQUEST_URI"]
         | 
| 154 | 
            +
                      url = (@env["SCRIPT_NAME"] || File.expand_path($0)).dup
         | 
| 155 | 
            +
                      url << @env["PATH_INFO"].to_s
         | 
| 156 | 
            +
                      url = WEBrick::HTTPUtils.escape_path(url)
         | 
| 157 | 
            +
                      if query_string = @env["QUERY_STRING"]
         | 
| 158 | 
            +
                        unless query_string.empty?
         | 
| 159 | 
            +
                          url << "?" << query_string
         | 
| 160 | 
            +
                        end
         | 
| 161 | 
            +
                      end
         | 
| 162 | 
            +
                    end
         | 
| 163 | 
            +
                    # we cannot get real HTTP version of client ;)
         | 
| 164 | 
            +
                    httpv = @config[:HTTPVersion]
         | 
| 165 | 
            +
                    return "#{meth} #{url} HTTP/#{httpv}"
         | 
| 166 | 
            +
                  end
         | 
| 167 | 
            +
              
         | 
| 168 | 
            +
                  def setup_header
         | 
| 169 | 
            +
                    add_header("CONTENT_TYPE", "Content-Type")
         | 
| 170 | 
            +
                    add_header("CONTENT_LENGTH", "Content-length")
         | 
| 171 | 
            +
                    @env.each_key{|name|
         | 
| 172 | 
            +
                      if /^HTTP_(.*)/ =~ name
         | 
| 173 | 
            +
                        add_header(name, $1.gsub(/_/, "-"))
         | 
| 174 | 
            +
                      end
         | 
| 175 | 
            +
                    }
         | 
| 176 | 
            +
                  end
         | 
| 177 | 
            +
              
         | 
| 178 | 
            +
                  def add_header(envname, hdrname)
         | 
| 179 | 
            +
                    if value = @env[envname]
         | 
| 180 | 
            +
                      unless value.empty?
         | 
| 181 | 
            +
                        @header_part << hdrname << ": " << value << CRLF
         | 
| 182 | 
            +
                      end
         | 
| 183 | 
            +
                    end
         | 
| 184 | 
            +
                  end
         | 
| 185 | 
            +
             | 
| 186 | 
            +
                  def input
         | 
| 187 | 
            +
                    @header_part.eof? ? @body_part : @header_part
         | 
| 188 | 
            +
                  end
         | 
| 189 | 
            +
              
         | 
| 190 | 
            +
                  public
         | 
| 191 | 
            +
              
         | 
| 192 | 
            +
                  def peeraddr
         | 
| 193 | 
            +
                    [nil, @remote_port, @remote_host, @remote_addr]
         | 
| 194 | 
            +
                  end
         | 
| 195 | 
            +
              
         | 
| 196 | 
            +
                  def addr
         | 
| 197 | 
            +
                    [nil, @server_port, @server_name, @server_addr]
         | 
| 198 | 
            +
                  end
         | 
| 199 | 
            +
              
         | 
| 200 | 
            +
                  def gets(eol=LF)
         | 
| 201 | 
            +
                    input.gets(eol)
         | 
| 202 | 
            +
                  end
         | 
| 203 | 
            +
              
         | 
| 204 | 
            +
                  def read(size=nil)
         | 
| 205 | 
            +
                    input.read(size)
         | 
| 206 | 
            +
                  end
         | 
| 207 | 
            +
             | 
| 208 | 
            +
                  def each
         | 
| 209 | 
            +
                    input.each{|line| yield(line) }
         | 
| 210 | 
            +
                  end
         | 
| 211 | 
            +
              
         | 
| 212 | 
            +
                  def <<(data)
         | 
| 213 | 
            +
                    @out_port << data
         | 
| 214 | 
            +
                  end
         | 
| 215 | 
            +
             | 
| 216 | 
            +
                  def cert
         | 
| 217 | 
            +
                    return nil unless defined?(OpenSSL)
         | 
| 218 | 
            +
                    if pem = @env["SSL_SERVER_CERT"]
         | 
| 219 | 
            +
                      OpenSSL::X509::Certificate.new(pem) unless pem.empty?
         | 
| 220 | 
            +
                    end
         | 
| 221 | 
            +
                  end
         | 
| 222 | 
            +
             | 
| 223 | 
            +
                  def peer_cert
         | 
| 224 | 
            +
                    return nil unless defined?(OpenSSL)
         | 
| 225 | 
            +
                    if pem = @env["SSL_CLIENT_CERT"]
         | 
| 226 | 
            +
                      OpenSSL::X509::Certificate.new(pem) unless pem.empty?
         | 
| 227 | 
            +
                    end
         | 
| 228 | 
            +
                  end
         | 
| 229 | 
            +
             | 
| 230 | 
            +
                  def peer_cert_chain
         | 
| 231 | 
            +
                    return nil unless defined?(OpenSSL)
         | 
| 232 | 
            +
                    if @env["SSL_CLIENT_CERT_CHAIN_0"]
         | 
| 233 | 
            +
                      keys = @env.keys
         | 
| 234 | 
            +
                      certs = keys.sort.collect{|k|
         | 
| 235 | 
            +
                        if /^SSL_CLIENT_CERT_CHAIN_\d+$/ =~ k
         | 
| 236 | 
            +
                          if pem = @env[k]
         | 
| 237 | 
            +
                            OpenSSL::X509::Certificate.new(pem) unless pem.empty?
         | 
| 238 | 
            +
                          end
         | 
| 239 | 
            +
                        end
         | 
| 240 | 
            +
                      }
         | 
| 241 | 
            +
                      certs.compact
         | 
| 242 | 
            +
                    end
         | 
| 243 | 
            +
                  end
         | 
| 244 | 
            +
             | 
| 245 | 
            +
                  def cipher
         | 
| 246 | 
            +
                    return nil unless defined?(OpenSSL)
         | 
| 247 | 
            +
                    if cipher = @env["SSL_CIPHER"]
         | 
| 248 | 
            +
                      ret = [ cipher ]
         | 
| 249 | 
            +
                      ret << @env["SSL_PROTOCOL"]
         | 
| 250 | 
            +
                      ret << @env["SSL_CIPHER_USEKEYSIZE"]
         | 
| 251 | 
            +
                      ret << @env["SSL_CIPHER_ALGKEYSIZE"]
         | 
| 252 | 
            +
                      ret
         | 
| 253 | 
            +
                    end
         | 
| 254 | 
            +
                  end
         | 
| 255 | 
            +
                end
         | 
| 256 | 
            +
              end 
         | 
| 257 | 
            +
            end  
         |