class WEBrick::HTTPServlet::FileHandler

def set_filename(req, res)

def set_filename(req, res)
  res.filename = @root
  path_info = req.path_info.scan(%r|/[^/]*|)
  path_info.unshift("")  # dummy for checking @root dir
  while base = path_info.first
    base = set_filesystem_encoding(base)
    break if base == "/"
    break unless File.directory?(File.expand_path(res.filename + base))
    shift_path_info(req, res, path_info)
    call_callback(:DirectoryCallback, req, res)
  end
  if base = path_info.first
    base = set_filesystem_encoding(base)
    if base == "/"
      if file = search_index_file(req, res)
        shift_path_info(req, res, path_info, file)
        call_callback(:FileCallback, req, res)
        return true
      end
      shift_path_info(req, res, path_info)
    elsif file = search_file(req, res, base)
      shift_path_info(req, res, path_info, file)
      call_callback(:FileCallback, req, res)
      return true
    else
      raise HTTPStatus::NotFound, "'#{req.path}' not found."
    end
  end
  return false
end