lib/rack/directory.rb in rack-0.9.1 vs lib/rack/directory.rb in rack-1.0.0
- old
+ new
@@ -1,6 +1,7 @@
require 'time'
+require 'rack/utils'
require 'rack/mime'
module Rack
# Rack::Directory serves entries below the +root+ given, according to the
# path info of the Rack request. If a directory is found, the file's contents
@@ -67,11 +68,11 @@
def check_forbidden
return unless @path_info.include? ".."
body = "Forbidden\n"
- size = body.respond_to?(:bytesize) ? body.bytesize : body.size
+ size = Rack::Utils.bytesize(body)
return [403, {"Content-Type" => "text/plain","Content-Length" => size.to_s}, [body]]
end
def list_directory
@files = [['../','Parent Directory','','','']]
@@ -86,10 +87,12 @@
url = F.join(@script_name, @path_info, basename)
size = stat.size
type = stat.directory? ? 'directory' : Mime.mime_type(ext)
size = stat.directory? ? '-' : filesize_format(size)
mtime = stat.mtime.httpdate
+ url << '/' if stat.directory?
+ basename << '/' if stat.directory?
@files << [ url, basename, size, type, mtime ]
end
return [ 200, {'Content-Type'=>'text/html; charset=utf-8'}, self ]
@@ -117,10 +120,10 @@
return entity_not_found
end
def entity_not_found
body = "Entity not found: #{@path_info}\n"
- size = body.respond_to?(:bytesize) ? body.bytesize : body.size
+ size = Rack::Utils.bytesize(body)
return [404, {"Content-Type" => "text/plain", "Content-Length" => size.to_s}, [body]]
end
def each
show_path = @path.sub(/^#{@root}/,'')