123456789_123456789_123456789_123456789_123456789_

Class: WEBrick::HTTPServlet::FileHandler

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: WEBrick::HTTPServlet::AbstractServlet
Defined in: lib/webrick/httpservlet/filehandler.rb

Overview

Serves a directory including fancy indexing and a variety of other options.

Example:

server.mount '/assets', WEBrick::FileHandler, '/path/to/assets'

Class Method Summary

AbstractServlet - Inherited

.get_instance

Factory for servlet instances that will handle a request from server using options from the mount point.

.new

Initializes a new servlet for server using options which are stored as-is in @options.

Instance Method Summary

AbstractServlet - Inherited

#do_GET

Raises a NotFound exception.

#do_HEAD

Dispatches to do_GET.

#do_OPTIONS

Returns the allowed HTTP request methods.

#service

Dispatches to a do_ method based on req if such a method is available.

#redirect_to_directory_uri

Redirects to a path ending in /.

Constructor Details

.new(server, root, options = {}, default = Config::FileHandler) ⇒ FileHandler

Creates a FileHandler servlet on server that serves files starting at directory ::

options may be a Hash containing keys from Config::FileHandler or true or false.

If options is true or false then :FancyIndexing is enabled or disabled respectively.

[ GitHub ]

  
# File 'lib/webrick/httpservlet/filehandler.rb', line 202

def initialize(server, root, options={}, default=Config::FileHandler)
  @config = server.config
  @logger = @config[:Logger]
  @root = File.expand_path(root)
  if options == true || options == false
    options = { :FancyIndexing => options }
  end
  @options = default.dup.update(options)
end

Class Method Details

.add_handler(suffix, handler)

Allow custom handling of requests for files with suffix by class handler

[ GitHub ]

  
# File 'lib/webrick/httpservlet/filehandler.rb', line 181

def self.add_handler(suffix, handler)
  HandlerTable[suffix] = handler
end

.remove_handler(suffix)

Remove custom handling of requests for files with suffix

[ GitHub ]

  
# File 'lib/webrick/httpservlet/filehandler.rb', line 188

def self.remove_handler(suffix)
  HandlerTable.delete(suffix)
end