def publish(script_name, request, response, logger)
logger.debug("enter document: #{self.class}")
script_name2, path = request.subpath(script_name)
local_path = File.expand_path(@root + http2local(path))
if (local_path[0, @root.length] != @root) then
logger.info("illegal path: #{request.path.inspect}")
raise HTTPError.new(403, "illegal path: #{request.path.inspect}")
end
response.doc_path = request.path
if (File.file? local_path) then
response.local_path = local_path
publish_file(path, local_path, request, response)
elsif (File.directory? local_path) then
if (path =~ %r|/$|) then
[ 'index.html',
'index.htm'
].each do |index_html|
index_path = File.join(local_path, index_html)
if (File.file? index_path) then
response.local_path = index_path
publish_file(path + index_html, index_path, request, response)
return
end
end
response.local_path = local_path
@dir_index.publish(script_name, request, response, logger)
else
response.local_path = local_path
response.status = 301
response.set_header('Location', 'http://' + request.host + request.path + '/')
response.set_header('Content-Type', 'text/html')
response.start_body
if (request.method != 'HEAD') then
response << "Directory.\n"
end
end
else
raise HTTPError.new(404)
end
nil
end