1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/webrick: Add Documentation

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
drbrain 2011-05-10 00:13:58 +00:00
parent 7e3ec1db0d
commit 071a678a15
12 changed files with 591 additions and 18 deletions

View file

@ -125,17 +125,48 @@ module WEBrick
end
end
##
# Serves files from a directory
class FileHandler < AbstractServlet
HandlerTable = Hash.new
##
# Allow custom handling of requests for files with +suffix+ by class
# +handler+
def self.add_handler(suffix, handler)
HandlerTable[suffix] = handler
end
##
# Remove custom handling of requests for files with +suffix+
def self.remove_handler(suffix)
HandlerTable.delete(suffix)
end
##
# Creates a FileHandler servlet on +server+ that serves files starting
# at directory +root+
#
# If +options+ is a Hash the following keys are allowed:
#
# :AcceptableLanguages:: Array of languages allowed for accept-language
# :DirectoryCallback:: Allows preprocessing of directory requests
# :FancyIndexing:: If true, show an index for directories
# :FileCallback:: Allows preprocessing of file requests
# :HandlerCallback:: Allows preprocessing of requests
# :HandlerTable:: Maps file suffixes to file handlers.
# DefaultFileHandler is used by default but any servlet
# can be used.
# :NondisclosureName:: Do not show files matching this array of globs
# :UserDir:: Directory inside ~user to serve content from for /~user
# requests. Only works if mounted on /
#
# If +options+ is true or false then +:FancyIndexing+ is enabled or
# disabled respectively.
def initialize(server, root, options={}, default=Config::FileHandler)
@config = server.config
@logger = @config[:Logger]