instance method
each_candidate_filepath
Ruby on Rails edge
Since v6.1.7.10 Private — implementation detail, not part of the public APISignature
each_candidate_filepath(path_info)
No documentation comment.
Parameters
-
path_inforeq
Source
# File actionpack/lib/action_dispatch/middleware/static.rb, line 181
def each_candidate_filepath(path_info)
return unless path = clean_path(path_info)
# Most requests are for dynamic routes with nothing like them under the
# root directory. Probe the path's first segment once before building
# and stat(2)ing each candidate: when "/users" doesn't exist, neither
# can "/users/1", "/users/1.html", or "/users/1/index.html".
root = path == "/"
slash = path.index("/", 1)
top_level = slash ? path[1...slash] : path[1..]
top_level_exists = !root && root_entry?(top_level)
ext = ::File.extname(path)
content_type = ::Rack::Mime.mime_type(ext, nil)
yield path, content_type || "text/plain" if top_level_exists
# Tack on .html and /index.html only for paths that don't have an explicit,
# resolvable file extension. No need to check for foo.js.html and
# foo.js/index.html.
unless content_type
default_ext = ::ActionController::Base.default_static_extension
if ext != default_ext
default_content_type = ::Rack::Mime.mime_type(default_ext, "text/plain")
# A top-level "/foo" may be served by "foo.html" rather than by an
# entry named "foo", so probe for that name instead.
if slash ? top_level_exists : root_entry?("#{top_level}#{default_ext}")
yield "#{path}#{default_ext}", default_content_type
end
if root
yield "/#{@index}#{default_ext}", default_content_type if root_entry?("#{@index}#{default_ext}")
elsif top_level_exists
yield "#{path}/#{@index}#{default_ext}", default_content_type
end
end
end
nil
end
Defined in actionpack/lib/action_dispatch/middleware/static.rb line 181
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionDispatch::FileHandler