1# frozen_string_literal: false
2#
3# config.rb -- Default configurations.
4#
5# Author: IPR -- Internet Programming with Ruby -- writers
6# Copyright (c) 2000, 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
7# Copyright (c) 2003 Internet Programming with Ruby writers. All rights
8# reserved.
9#
10# $IPR: config.rb,v 1.52 2003/07/22 19:20:42 gotoyuzo Exp $
11
12require_relative 'version'
13require_relative 'httpversion'
14require_relative 'httputils'
15require_relative 'utils'
16require_relative 'log'
17
18module WEBrick
19  module Config
20    LIBDIR = File::dirname(__FILE__) # :nodoc:
21
22    # for GenericServer
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(
31      :BindAddress    => nil,   # "0.0.0.0" or "::" or nil
32      :Port           => nil,   # users MUST specify this!!
33      :MaxClients     => 100,   # maximum number of the concurrent connections
34      :ServerType     => nil,   # default: WEBrick::SimpleServer
35      :Logger         => nil,   # default: WEBrick::Log.new
36      :ServerSoftware => "WEBrick/#{WEBrick::VERSION} " +
37                         "(Ruby/#{RUBY_VERSION}/#{RUBY_RELEASE_DATE})",
38      :TempDir        => ENV['TMPDIR']||ENV['TMP']||ENV['TEMP']||'/tmp',
39      :DoNotListen    => false,
40      :StartCallback  => nil,
41      :StopCallback   => nil,
42      :AcceptCallback => nil,
43      :DoNotReverseLookup => true,
44      :ShutdownSocketWithoutClose => false,
45    )
46
47    # for HTTPServer, HTTPRequest, HTTPResponse ...
48    HTTP = General.dup.update(
49      :Port           => 80,
50      :RequestTimeout => 30,
51      :HTTPVersion    => HTTPVersion.new("1.1"),
52      :AccessLog      => nil,
53      :MimeTypes      => HTTPUtils::DefaultMimeTypes,
54      :DirectoryIndex => ["index.html","index.htm","index.cgi","index.rhtml"],
55      :DocumentRoot   => nil,
56      :DocumentRootOptions => { :FancyIndexing => true },
57      :RequestCallback => nil,
58      :ServerAlias    => nil,
59      :InputBufferSize  => 65536, # input buffer size in reading request body
60      :OutputBufferSize => 65536, # output buffer size in sending File or IO
61
62      # for HTTPProxyServer
63      :ProxyAuthProc  => nil,
64      :ProxyContentHandler => nil,
65      :ProxyVia       => true,
66      :ProxyTimeout   => true,
67      :ProxyURI       => nil,
68
69      :CGIInterpreter => nil,
70      :CGIPathEnv     => nil,
71
72      # workaround: if Request-URIs contain 8bit chars,
73      # they should be escaped before calling of URI::parse().
74      :Escape8bitURI  => false
75    )
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
101    FileHandler = {
102      :NondisclosureName => [".ht*", "*~"],
103      :FancyIndexing     => false,
104      :HandlerTable      => {},
105      :HandlerCallback   => nil,
106      :DirectoryCallback => nil,
107      :FileCallback      => nil,
108      :UserDir           => nil,  # e.g. "public_html"
109      :AcceptableLanguages => []  # ["en", "ja", ... ]
110    }
111
112    ##
113    # Default configuration for WEBrick::HTTPAuth::BasicAuth
114    #
115    # :AutoReloadUserDB:: Reload the user database provided by :UserDB
116    #                     automatically?
117
118    BasicAuth = {
119      :AutoReloadUserDB     => true,
120    }
121
122    ##
123    # Default configuration for WEBrick::HTTPAuth::DigestAuth.
124    #
125    # :Algorithm:: MD5, MD5-sess (default), SHA1, SHA1-sess
126    # :Domain:: An Array of URIs that define the protected space
127    # :Qop:: 'auth' for authentication, 'auth-int' for integrity protection or
128    #        both
129    # :UseOpaque:: Should the server send opaque values to the client?  This
130    #              helps prevent replay attacks.
131    # :CheckNc:: Should the server check the nonce count?  This helps the
132    #            server detect replay attacks.
133    # :UseAuthenticationInfoHeader:: Should the server send an
134    #                                AuthenticationInfo header?
135    # :AutoReloadUserDB:: Reload the user database provided by :UserDB
136    #                     automatically?
137    # :NonceExpirePeriod:: How long should we store used nonces?  Default is
138    #                      30 minutes.
139    # :NonceExpireDelta:: How long is a nonce valid?  Default is 1 minute
140    # :InternetExplorerHack:: Hack which allows Internet Explorer to work.
141    # :OperaHack:: Hack which allows Opera to work.
142
143    DigestAuth = {
144      :Algorithm            => 'MD5-sess', # or 'MD5'
145      :Domain               => nil,        # an array includes domain names.
146      :Qop                  => [ 'auth' ], # 'auth' or 'auth-int' or both.
147      :UseOpaque            => true,
148      :UseNextNonce         => false,
149      :CheckNc              => false,
150      :UseAuthenticationInfoHeader => true,
151      :AutoReloadUserDB     => true,
152      :NonceExpirePeriod    => 30*60,
153      :NonceExpireDelta     => 60,
154      :InternetExplorerHack => true,
155      :OperaHack            => true,
156    }
157  end
158end
159