Sha256: ba603b4bb3b3b9172f7190014b2c5837c098ca4b5825f9cb1b9f0ae2be92317d
Contents?: true
Size: 964 Bytes
Versions: 31
Compression:
Stored size: 964 Bytes
Contents
# This file is part of the "Utopia Framework" project, and is licensed under the GNU AGPLv3. # Copyright 2010 Samuel Williams. All rights reserved. # See <utopia.rb> for licensing details. require 'utopia/middleware' require 'utopia/path' module Utopia module Middleware class DirectoryIndex def initialize(app, options = {}) @app = app @root = options[:root] || Utopia::Middleware::default_root @files = ["index.html"] @default = "index" end def call(env) path = Path.create(env["PATH_INFO"]) if path.directory? # Check to see if one of the files exists in the requested directory @files.each do |file| if File.exist?(File.join(@root, path.components, file)) return [307, {"Location" => (path + file).to_s}, []] end end # Use the default path return [307, {"Location" => (path + @default).to_s}, []] else return @app.call(env) end end end end end
Version data entries
31 entries across 31 versions & 1 rubygems