# WEBrick::HTTPServlet::FileHandler (Class)

In: | webrick/httpservlet/filehandler.rb
Parent: | AbstractServlet

## Methods

add_handler do_GET do_OPTIONS do_POST new remove_handler service

## Constants

HandlerTable | = | Hash.new(DefaultFileHandler)

## Public Class methods

add_handler(suffix, handler)

[Source]

    # File webrick/httpservlet/filehandler.rb, line 127
          def self.add_handler(suffix, handler)
            HandlerTable[suffix] = handler
          end

remove_handler(suffix)

[Source]

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

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

[Source]

    # File webrick/httpservlet/filehandler.rb, line 135
          def initialize(server, root, options={}, default=Config::FileHandler)
            @config = server.config
            @logger = @config[:Logger]
            @root = root
            if options == true || options == false
              options = { :FancyIndexing => options }
            end
            @options = default.dup.update(options)
          end

## Public Instance methods

service(req, res)

[Source]

    # File webrick/httpservlet/filehandler.rb, line 145
          def service(req, res)
            # if this class is mounted on "/" and /~username is requested.

            # we're going to override path informations before invoking service.

            if defined?(Etc) && @options[:UserDir] && req.script_name.empty?
              if %|^(/~([^/]+))| =~ req.path_info
                script_name, user = $1, $2
                path_info = $'
                begin
                  passwd = Etc::getpwnam(user)
                  @root = File::join(passwd.dir, @options[:UserDir])
                  req.script_name = script_name
                  req.path_info = path_info
                rescue
                  @logger.debug "#{self.class}#do_GET: getpwnam(#{user}) failed"
                end
              end
            end
            super(req, res)
          end

do_GET(req, res)

[Source]

    # File webrick/httpservlet/filehandler.rb, line 165
          def do_GET(req, res)
            unless exec_handler(req, res)
              set_dir_list(req, res)
            end
          end

do_POST(req, res)

[Source]

    # File webrick/httpservlet/filehandler.rb, line 171
          def do_POST(req, res)
            unless exec_handler(req, res)
              raise HTTPStatus::NotFound, "`#{req.path}' not found."
            end
          end

do_OPTIONS(req, res)

[Source]

    # File webrick/httpservlet/filehandler.rb, line 177
          def do_OPTIONS(req, res)
            unless exec_handler(req, res)
              super(req, res)
            end
          end

[Validate]