In Files

  • webrick/httpservlet/filehandler.rb

WEBrick::HTTPServlet::FileHandler

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

Example:

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

Public Class Methods

add_handler(suffix, handler) click to toggle source

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

 
               # File webrick/httpservlet/filehandler.rb, line 162
def self.add_handler(suffix, handler)
  HandlerTable[suffix] = handler
end
            
new(server, root, options={}, default=Config::FileHandler) click to toggle source

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

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

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

 
               # File webrick/httpservlet/filehandler.rb, line 183
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
            
remove_handler(suffix) click to toggle source

Remove custom handling of requests for files with suffix

 
               # File webrick/httpservlet/filehandler.rb, line 169
def self.remove_handler(suffix)
  HandlerTable.delete(suffix)
end
            

Commenting is here to help enhance the documentation. For example, sample code, or clarification of the documentation.

If you are posting code samples in your comments, please wrap them in "<pre><code class="ruby" > ... </code></pre>" markup in order to get syntax highlighting.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file a bug report so that it can be corrected for the next release. Thank you.

blog comments powered by Disqus