2003-07-23 12:51:36 -04:00
|
|
|
#
|
|
|
|
# filehandler.rb -- FileHandler Module
|
|
|
|
#
|
|
|
|
# Author: IPR -- Internet Programming with Ruby -- writers
|
|
|
|
# Copyright (c) 2001 TAKAHASHI Masayoshi, GOTOU Yuuzou
|
|
|
|
# Copyright (c) 2003 Internet Programming with Ruby writers. All rights
|
|
|
|
# reserved.
|
|
|
|
#
|
|
|
|
# $IPR: filehandler.rb,v 1.44 2003/06/07 01:34:51 gotoyuzo Exp $
|
|
|
|
|
|
|
|
require 'thread'
|
|
|
|
require 'time'
|
|
|
|
|
|
|
|
require 'webrick/htmlutils'
|
|
|
|
require 'webrick/httputils'
|
|
|
|
require 'webrick/httpstatus'
|
|
|
|
|
|
|
|
module WEBrick
|
|
|
|
module HTTPServlet
|
|
|
|
|
|
|
|
class DefaultFileHandler < AbstractServlet
|
|
|
|
def initialize(server, local_path)
|
2005-08-07 16:16:15 -04:00
|
|
|
super(server, local_path)
|
2003-07-23 12:51:36 -04:00
|
|
|
@local_path = local_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def do_GET(req, res)
|
|
|
|
st = File::stat(@local_path)
|
|
|
|
mtime = st.mtime
|
|
|
|
res['etag'] = sprintf("%x-%x-%x", st.ino, st.size, st.mtime.to_i)
|
|
|
|
|
|
|
|
if not_modified?(req, res, mtime, res['etag'])
|
|
|
|
res.body = ''
|
|
|
|
raise HTTPStatus::NotModified
|
2009-03-05 22:56:38 -05:00
|
|
|
elsif req['range']
|
2003-07-23 12:51:36 -04:00
|
|
|
make_partial_content(req, res, @local_path, st.size)
|
|
|
|
raise HTTPStatus::PartialContent
|
|
|
|
else
|
|
|
|
mtype = HTTPUtils::mime_type(@local_path, @config[:MimeTypes])
|
|
|
|
res['content-type'] = mtype
|
|
|
|
res['content-length'] = st.size
|
|
|
|
res['last-modified'] = mtime.httpdate
|
|
|
|
res.body = open(@local_path, "rb")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def not_modified?(req, res, mtime, etag)
|
|
|
|
if ir = req['if-range']
|
|
|
|
begin
|
|
|
|
if Time.httpdate(ir) >= mtime
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
rescue
|
2006-01-09 00:27:43 -05:00
|
|
|
if HTTPUtils::split_header_value(ir).member?(res['etag'])
|
2003-07-23 12:51:36 -04:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if (ims = req['if-modified-since']) && Time.parse(ims) >= mtime
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
if (inm = req['if-none-match']) &&
|
|
|
|
HTTPUtils::split_header_value(inm).member?(res['etag'])
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
def make_partial_content(req, res, filename, filesize)
|
|
|
|
mtype = HTTPUtils::mime_type(filename, @config[:MimeTypes])
|
|
|
|
unless ranges = HTTPUtils::parse_range_header(req['range'])
|
2004-08-13 00:11:30 -04:00
|
|
|
raise HTTPStatus::BadRequest,
|
|
|
|
"Unrecognized range-spec: \"#{req['range']}\""
|
2003-07-23 12:51:36 -04:00
|
|
|
end
|
|
|
|
open(filename, "rb"){|io|
|
|
|
|
if ranges.size > 1
|
2004-08-13 00:11:30 -04:00
|
|
|
time = Time.now
|
2003-07-23 12:51:36 -04:00
|
|
|
boundary = "#{time.sec}_#{time.usec}_#{Process::pid}"
|
|
|
|
body = ''
|
2004-08-13 00:11:30 -04:00
|
|
|
ranges.each{|range|
|
2003-07-23 12:51:36 -04:00
|
|
|
first, last = prepare_range(range, filesize)
|
|
|
|
next if first < 0
|
|
|
|
io.pos = first
|
|
|
|
content = io.read(last-first+1)
|
|
|
|
body << "--" << boundary << CRLF
|
|
|
|
body << "Content-Type: #{mtype}" << CRLF
|
2010-01-18 03:16:07 -05:00
|
|
|
body << "Content-Range: bytes #{first}-#{last}/#{filesize}" << CRLF
|
2003-07-23 12:51:36 -04:00
|
|
|
body << CRLF
|
|
|
|
body << content
|
|
|
|
body << CRLF
|
|
|
|
}
|
|
|
|
raise HTTPStatus::RequestRangeNotSatisfiable if body.empty?
|
|
|
|
body << "--" << boundary << "--" << CRLF
|
2004-08-13 00:11:30 -04:00
|
|
|
res["content-type"] = "multipart/byteranges; boundary=#{boundary}"
|
|
|
|
res.body = body
|
2003-07-23 12:51:36 -04:00
|
|
|
elsif range = ranges[0]
|
|
|
|
first, last = prepare_range(range, filesize)
|
|
|
|
raise HTTPStatus::RequestRangeNotSatisfiable if first < 0
|
|
|
|
if last == filesize - 1
|
|
|
|
content = io.dup
|
|
|
|
content.pos = first
|
|
|
|
else
|
|
|
|
io.pos = first
|
|
|
|
content = io.read(last-first+1)
|
|
|
|
end
|
|
|
|
res['content-type'] = mtype
|
2010-01-18 03:16:07 -05:00
|
|
|
res['content-range'] = "bytes #{first}-#{last}/#{filesize}"
|
2003-07-23 12:51:36 -04:00
|
|
|
res['content-length'] = last - first + 1
|
|
|
|
res.body = content
|
|
|
|
else
|
|
|
|
raise HTTPStatus::BadRequest
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def prepare_range(range, filesize)
|
|
|
|
first = range.first < 0 ? filesize + range.first : range.first
|
|
|
|
return -1, -1 if first < 0 || first >= filesize
|
|
|
|
last = range.last < 0 ? filesize + range.last : range.last
|
|
|
|
last = filesize - 1 if last >= filesize
|
|
|
|
return first, last
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-09 20:13:58 -04:00
|
|
|
##
|
|
|
|
# Serves files from a directory
|
|
|
|
|
2003-07-23 12:51:36 -04:00
|
|
|
class FileHandler < AbstractServlet
|
2004-10-12 08:26:39 -04:00
|
|
|
HandlerTable = Hash.new
|
2003-07-23 12:51:36 -04:00
|
|
|
|
2011-05-09 20:13:58 -04:00
|
|
|
##
|
|
|
|
# Allow custom handling of requests for files with +suffix+ by class
|
|
|
|
# +handler+
|
|
|
|
|
2003-07-23 12:51:36 -04:00
|
|
|
def self.add_handler(suffix, handler)
|
|
|
|
HandlerTable[suffix] = handler
|
|
|
|
end
|
|
|
|
|
2011-05-09 20:13:58 -04:00
|
|
|
##
|
|
|
|
# Remove custom handling of requests for files with +suffix+
|
|
|
|
|
2003-07-23 12:51:36 -04:00
|
|
|
def self.remove_handler(suffix)
|
|
|
|
HandlerTable.delete(suffix)
|
|
|
|
end
|
|
|
|
|
2011-05-09 20:13:58 -04:00
|
|
|
##
|
|
|
|
# Creates a FileHandler servlet on +server+ that serves files starting
|
|
|
|
# at directory +root+
|
|
|
|
#
|
|
|
|
# If +options+ is a Hash the following keys are allowed:
|
2011-05-15 07:55:52 -04:00
|
|
|
#
|
2011-05-09 20:13:58 -04:00
|
|
|
# :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.
|
2011-05-15 07:55:52 -04:00
|
|
|
|
2003-07-23 12:51:36 -04:00
|
|
|
def initialize(server, root, options={}, default=Config::FileHandler)
|
|
|
|
@config = server.config
|
|
|
|
@logger = @config[:Logger]
|
2004-09-16 05:14:27 -04:00
|
|
|
@root = File.expand_path(root)
|
2003-07-23 12:51:36 -04:00
|
|
|
if options == true || options == false
|
|
|
|
options = { :FancyIndexing => options }
|
|
|
|
end
|
|
|
|
@options = default.dup.update(options)
|
|
|
|
end
|
|
|
|
|
|
|
|
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 %r|^(/~([^/]+))| =~ 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
|
2008-03-03 09:31:30 -05:00
|
|
|
prevent_directory_traversal(req, res)
|
2003-07-23 12:51:36 -04:00
|
|
|
super(req, res)
|
|
|
|
end
|
|
|
|
|
|
|
|
def do_GET(req, res)
|
|
|
|
unless exec_handler(req, res)
|
|
|
|
set_dir_list(req, res)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def do_POST(req, res)
|
|
|
|
unless exec_handler(req, res)
|
|
|
|
raise HTTPStatus::NotFound, "`#{req.path}' not found."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def do_OPTIONS(req, res)
|
|
|
|
unless exec_handler(req, res)
|
|
|
|
super(req, res)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# ToDo
|
|
|
|
# RFC2518: HTTP Extensions for Distributed Authoring -- WEBDAV
|
|
|
|
#
|
|
|
|
# PROPFIND PROPPATCH MKCOL DELETE PUT COPY MOVE
|
|
|
|
# LOCK UNLOCK
|
|
|
|
|
|
|
|
# RFC3253: Versioning Extensions to WebDAV
|
|
|
|
# (Web Distributed Authoring and Versioning)
|
|
|
|
#
|
|
|
|
# VERSION-CONTROL REPORT CHECKOUT CHECK_IN UNCHECKOUT
|
|
|
|
# MKWORKSPACE UPDATE LABEL MERGE ACTIVITY
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2008-05-18 09:33:24 -04:00
|
|
|
def trailing_pathsep?(path)
|
|
|
|
# check for trailing path separator:
|
|
|
|
# File.dirname("/aaaa/bbbb/") #=> "/aaaa")
|
|
|
|
# File.dirname("/aaaa/bbbb/x") #=> "/aaaa/bbbb")
|
|
|
|
# File.dirname("/aaaa/bbbb") #=> "/aaaa")
|
|
|
|
# File.dirname("/aaaa/bbbbx") #=> "/aaaa")
|
|
|
|
return File.dirname(path) != File.dirname(path+"x")
|
|
|
|
end
|
|
|
|
|
2008-03-03 09:31:30 -05:00
|
|
|
def prevent_directory_traversal(req, res)
|
2008-05-18 09:33:24 -04:00
|
|
|
# Preventing directory traversal on Windows platforms;
|
2008-03-03 09:31:30 -05:00
|
|
|
# Backslashes (0x5c) in path_info are not interpreted as special
|
|
|
|
# character in URI notation. So the value of path_info should be
|
|
|
|
# normalize before accessing to the filesystem.
|
2008-05-18 09:33:24 -04:00
|
|
|
|
2010-06-17 12:26:00 -04:00
|
|
|
# dirty hack for filesystem encoding; in nature, File.expand_path
|
|
|
|
# should not be used for path normalization. [Bug #3345]
|
|
|
|
path = req.path_info.dup.force_encoding(Encoding.find("filesystem"))
|
2008-05-18 09:33:24 -04:00
|
|
|
if trailing_pathsep?(req.path_info)
|
2008-03-03 09:31:30 -05:00
|
|
|
# File.expand_path removes the trailing path separator.
|
|
|
|
# Adding a character is a workaround to save it.
|
|
|
|
# File.expand_path("/aaa/") #=> "/aaa"
|
|
|
|
# File.expand_path("/aaa/" + "x") #=> "/aaa/x"
|
2010-06-17 12:26:00 -04:00
|
|
|
expanded = File.expand_path(path + "x")
|
2008-05-18 09:33:24 -04:00
|
|
|
expanded.chop! # remove trailing "x"
|
|
|
|
else
|
2010-06-17 12:26:00 -04:00
|
|
|
expanded = File.expand_path(path)
|
2008-03-03 09:31:30 -05:00
|
|
|
end
|
2010-06-17 12:26:00 -04:00
|
|
|
expanded.force_encoding(req.path_info.encoding)
|
2008-05-18 09:33:24 -04:00
|
|
|
req.path_info = expanded
|
2008-03-03 09:31:30 -05:00
|
|
|
end
|
|
|
|
|
2003-07-23 12:51:36 -04:00
|
|
|
def exec_handler(req, res)
|
|
|
|
raise HTTPStatus::NotFound, "`#{req.path}' not found" unless @root
|
|
|
|
if set_filename(req, res)
|
2008-05-18 09:33:24 -04:00
|
|
|
handler = get_handler(req, res)
|
2003-07-23 12:51:36 -04:00
|
|
|
call_callback(:HandlerCallback, req, res)
|
|
|
|
h = handler.get_instance(@config, res.filename)
|
|
|
|
h.service(req, res)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
call_callback(:HandlerCallback, req, res)
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2008-05-18 09:33:24 -04:00
|
|
|
def get_handler(req, res)
|
|
|
|
suffix1 = (/\.(\w+)\z/ =~ res.filename) && $1.downcase
|
|
|
|
if /\.(\w+)\.([\w\-]+)\z/ =~ res.filename
|
|
|
|
if @options[:AcceptableLanguages].include?($2.downcase)
|
|
|
|
suffix2 = $1.downcase
|
|
|
|
end
|
|
|
|
end
|
2004-10-12 08:26:39 -04:00
|
|
|
handler_table = @options[:HandlerTable]
|
|
|
|
return handler_table[suffix1] || handler_table[suffix2] ||
|
|
|
|
HandlerTable[suffix1] || HandlerTable[suffix2] ||
|
|
|
|
DefaultFileHandler
|
|
|
|
end
|
|
|
|
|
2003-07-23 12:51:36 -04:00
|
|
|
def set_filename(req, res)
|
|
|
|
res.filename = @root.dup
|
|
|
|
path_info = req.path_info.scan(%r|/[^/]*|)
|
|
|
|
|
2004-10-12 08:26:39 -04:00
|
|
|
path_info.unshift("") # dummy for checking @root dir
|
|
|
|
while base = path_info.first
|
|
|
|
break if base == "/"
|
2008-05-18 09:33:24 -04:00
|
|
|
break unless File.directory?(File.expand_path(res.filename + base))
|
2004-10-12 08:26:39 -04:00
|
|
|
shift_path_info(req, res, path_info)
|
|
|
|
call_callback(:DirectoryCallback, req, res)
|
|
|
|
end
|
2003-07-23 12:51:36 -04:00
|
|
|
|
2004-10-12 08:26:39 -04:00
|
|
|
if base = path_info.first
|
|
|
|
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)
|
2003-07-23 12:51:36 -04:00
|
|
|
call_callback(:FileCallback, req, res)
|
|
|
|
return true
|
2004-10-12 08:26:39 -04:00
|
|
|
else
|
|
|
|
raise HTTPStatus::NotFound, "`#{req.path}' not found."
|
2003-07-23 12:51:36 -04:00
|
|
|
end
|
|
|
|
end
|
2004-10-12 08:26:39 -04:00
|
|
|
|
2003-07-23 12:51:36 -04:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2004-12-15 03:47:49 -05:00
|
|
|
def check_filename(req, res, name)
|
2008-05-18 09:33:24 -04:00
|
|
|
if nondisclosure_name?(name) || windows_ambiguous_name?(name)
|
|
|
|
@logger.warn("the request refers nondisclosure name `#{name}'.")
|
|
|
|
raise HTTPStatus::NotFound, "`#{req.path}' not found."
|
|
|
|
end
|
2004-10-12 08:26:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def shift_path_info(req, res, path_info, base=nil)
|
|
|
|
tmp = path_info.shift
|
|
|
|
base = base || tmp
|
|
|
|
req.path_info = path_info.join
|
|
|
|
req.script_name << base
|
2008-05-18 09:33:24 -04:00
|
|
|
res.filename = File.expand_path(res.filename + base)
|
|
|
|
check_filename(req, res, File.basename(res.filename))
|
2004-10-12 08:26:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def search_index_file(req, res)
|
|
|
|
@config[:DirectoryIndex].each{|index|
|
|
|
|
if file = search_file(req, res, "/"+index)
|
|
|
|
return file
|
|
|
|
end
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def search_file(req, res, basename)
|
|
|
|
langs = @options[:AcceptableLanguages]
|
|
|
|
path = res.filename + basename
|
|
|
|
if File.file?(path)
|
|
|
|
return basename
|
|
|
|
elsif langs.size > 0
|
|
|
|
req.accept_language.each{|lang|
|
|
|
|
path_with_lang = path + ".#{lang}"
|
|
|
|
if langs.member?(lang) && File.file?(path_with_lang)
|
|
|
|
return basename + ".#{lang}"
|
|
|
|
end
|
|
|
|
}
|
|
|
|
(langs - req.accept_language).each{|lang|
|
|
|
|
path_with_lang = path + ".#{lang}"
|
|
|
|
if File.file?(path_with_lang)
|
|
|
|
return basename + ".#{lang}"
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2003-07-23 12:51:36 -04:00
|
|
|
def call_callback(callback_name, req, res)
|
|
|
|
if cb = @options[callback_name]
|
|
|
|
cb.call(req, res)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-05-18 09:33:24 -04:00
|
|
|
def windows_ambiguous_name?(name)
|
|
|
|
return true if /[. ]+\z/ =~ name
|
|
|
|
return true if /::\$DATA\z/ =~ name
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2004-12-15 03:47:49 -05:00
|
|
|
def nondisclosure_name?(name)
|
|
|
|
@options[:NondisclosureName].each{|pattern|
|
2008-03-03 09:31:30 -05:00
|
|
|
if File.fnmatch(pattern, name, File::FNM_CASEFOLD)
|
2004-12-15 03:47:49 -05:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2003-07-23 12:51:36 -04:00
|
|
|
def set_dir_list(req, res)
|
|
|
|
redirect_to_directory_uri(req, res)
|
|
|
|
unless @options[:FancyIndexing]
|
|
|
|
raise HTTPStatus::Forbidden, "no access permission to `#{req.path}'"
|
|
|
|
end
|
|
|
|
local_path = res.filename
|
|
|
|
list = Dir::entries(local_path).collect{|name|
|
|
|
|
next if name == "." || name == ".."
|
2004-12-15 03:47:49 -05:00
|
|
|
next if nondisclosure_name?(name)
|
2008-05-18 09:33:24 -04:00
|
|
|
next if windows_ambiguous_name?(name)
|
|
|
|
st = (File::stat(File.join(local_path, name)) rescue nil)
|
2003-07-23 12:51:36 -04:00
|
|
|
if st.nil?
|
|
|
|
[ name, nil, -1 ]
|
|
|
|
elsif st.directory?
|
|
|
|
[ name + "/", st.mtime, -1 ]
|
|
|
|
else
|
|
|
|
[ name, st.mtime, st.size ]
|
|
|
|
end
|
|
|
|
}
|
|
|
|
list.compact!
|
|
|
|
|
|
|
|
if d0 = req.query["N"]; idx = 0
|
|
|
|
elsif d0 = req.query["M"]; idx = 1
|
|
|
|
elsif d0 = req.query["S"]; idx = 2
|
|
|
|
else d0 = "A" ; idx = 0
|
|
|
|
end
|
|
|
|
d1 = (d0 == "A") ? "D" : "A"
|
|
|
|
|
|
|
|
if d0 == "A"
|
|
|
|
list.sort!{|a,b| a[idx] <=> b[idx] }
|
|
|
|
else
|
|
|
|
list.sort!{|a,b| b[idx] <=> a[idx] }
|
|
|
|
end
|
|
|
|
|
|
|
|
res['content-type'] = "text/html"
|
|
|
|
|
|
|
|
res.body = <<-_end_of_html_
|
|
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
|
|
|
<HTML>
|
|
|
|
<HEAD><TITLE>Index of #{HTMLUtils::escape(req.path)}</TITLE></HEAD>
|
|
|
|
<BODY>
|
|
|
|
<H1>Index of #{HTMLUtils::escape(req.path)}</H1>
|
|
|
|
_end_of_html_
|
|
|
|
|
|
|
|
res.body << "<PRE>\n"
|
|
|
|
res.body << " <A HREF=\"?N=#{d1}\">Name</A> "
|
|
|
|
res.body << "<A HREF=\"?M=#{d1}\">Last modified</A> "
|
|
|
|
res.body << "<A HREF=\"?S=#{d1}\">Size</A>\n"
|
|
|
|
res.body << "<HR>\n"
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2008-05-18 09:33:24 -04:00
|
|
|
list.unshift [ "..", File::mtime(local_path+"/.."), -1 ]
|
2003-07-23 12:51:36 -04:00
|
|
|
list.each{ |name, time, size|
|
|
|
|
if name == ".."
|
|
|
|
dname = "Parent Directory"
|
2008-11-08 04:41:24 -05:00
|
|
|
elsif name.bytesize > 25
|
* ext/json/lib/json/pure/generator.rb,
ext/json/lib/json/pure/parser.rb, ext/openssl/lib/openssl/x509.rb,
ext/win32ole/sample/olegen.rb, lib/date/format.rb, lib/irb/context.rb,
lib/irb/workspace.rb, lib/net/http.rb, lib/net/imap.rb,
lib/rdoc/generator.rb, lib/rdoc/markup/to_html.rb,
lib/rdoc/markup/to_latex.rb, lib/rdoc/parsers/parse_c.rb,
lib/rdoc/ri/formatter.rb, lib/rexml/parsers/baseparser.rb,
lib/rexml/quickpath.rb, lib/rexml/text.rb, lib/rss/parser.rb,
lib/uri/common.rb, lib/uri/generic.rb, lib/webrick/httpresponse.rb,
lib/webrick/httpservlet/filehandler.rb, lib/yaml/baseemitter.rb,
lib/yaml/encoding.rb: performance tuning arround String#gsub.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15442 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-02-12 01:18:06 -05:00
|
|
|
dname = name.sub(/^(.{23})(?:.*)/, '\1..')
|
2003-07-23 12:51:36 -04:00
|
|
|
else
|
|
|
|
dname = name
|
|
|
|
end
|
2009-12-06 02:04:50 -05:00
|
|
|
s = " <A HREF=\"#{HTTPUtils::escape(name)}\">#{HTMLUtils::escape(dname)}</A>"
|
2008-11-08 04:41:24 -05:00
|
|
|
s << " " * (30 - dname.bytesize)
|
2003-07-23 12:51:36 -04:00
|
|
|
s << (time ? time.strftime("%Y/%m/%d %H:%M ") : " " * 22)
|
|
|
|
s << (size >= 0 ? size.to_s : "-") << "\n"
|
|
|
|
res.body << s
|
|
|
|
}
|
|
|
|
res.body << "</PRE><HR>"
|
|
|
|
|
2009-03-05 22:56:38 -05:00
|
|
|
res.body << <<-_end_of_html_
|
2003-07-23 12:51:36 -04:00
|
|
|
<ADDRESS>
|
|
|
|
#{HTMLUtils::escape(@config[:ServerSoftware])}<BR>
|
2003-09-08 05:52:34 -04:00
|
|
|
at #{req.host}:#{req.port}
|
2003-07-23 12:51:36 -04:00
|
|
|
</ADDRESS>
|
|
|
|
</BODY>
|
|
|
|
</HTML>
|
|
|
|
_end_of_html_
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|