From 14fc77f607e47f2adf77b31457d0c8a7a3300af6 Mon Sep 17 00:00:00 2001 From: evanweaver Date: Fri, 26 Oct 2007 02:01:39 +0000 Subject: close #15009 git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@739 19e92222-5c0b-0410-8929-a290d50e31e9 --- lib/mongrel/handlers.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/mongrel/handlers.rb b/lib/mongrel/handlers.rb index 05f585c..9981a18 100644 --- a/lib/mongrel/handlers.rb +++ b/lib/mongrel/handlers.rb @@ -98,6 +98,10 @@ module Mongrel # that the final expanded path includes the root path. If it doesn't # than it simply gives a 404. # + # If you pass nil as the root path, it will not check any locations or + # expand any paths. This lets you serve files from multiple directories + # on win32. + # # The default content type is "text/plain; charset=ISO-8859-1" but you # can change it anything you want using the DirHandler.default_content_type # attribute. @@ -110,9 +114,9 @@ module Mongrel ONLY_HEAD_GET="Only HEAD and GET allowed.".freeze - # You give it the path to the directory root and an (optional) + # You give it the path to the directory root and and optional listing_allowed and index_html def initialize(path, listing_allowed=true, index_html="index.html") - @path = File.expand_path(path) + @path = File.expand_path(path) if path @listing_allowed=listing_allowed @index_html = index_html @default_content_type = "application/octet-stream".freeze @@ -120,7 +124,13 @@ module Mongrel # Checks if the given path can be served and returns the full path (or nil if not). def can_serve(path_info) - req_path = File.expand_path(File.join(@path,HttpRequest.unescape(path_info)), @path) + + req_path = HttpRequest.unescape(path_info) + if @path + req_path = File.expand_path(File.join(@path, path_info), @path) + else + req_path = File.expand_path(req_path) + end if req_path.index(@path) == 0 and File.exist? req_path # it exists and it's in the right location -- cgit v1.2.3-24-ge0c7