From e4f07888ceca3c2ac11818a45cc3374537737e8e Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 20 Feb 2005 17:18:59 +0000 Subject: Made caching work for WEBrick and lighttpd by appending .html for all URLs not already containing a dot git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@715 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/lib/webrick_server.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'railties/lib') diff --git a/railties/lib/webrick_server.rb b/railties/lib/webrick_server.rb index 5814f87a06..22cdc9a845 100644 --- a/railties/lib/webrick_server.rb +++ b/railties/lib/webrick_server.rb @@ -6,6 +6,7 @@ require 'stringio' include WEBrick + class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet REQUEST_MUTEX = Mutex.new @@ -42,16 +43,28 @@ class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet def handle_file(req, res) begin + add_dot_html(req) @file_handler.send(:do_GET, req, res) + remove_dot_html(req) return true rescue HTTPStatus::PartialContent, HTTPStatus::NotModified => err res.set_error(err) return true rescue => err return false + ensure + remove_dot_html(req) end end + def add_dot_html(req) + if /^([^.]+)$/ =~ req.path then req.instance_variable_set(:@path_info, "#{$1}.html") end + end + + def remove_dot_html(req) + if /^([^.]+).html$/ =~ req.path then req.instance_variable_set(:@path_info, $1) end + end + def handle_dispatch(req, res, origin = nil) env = req.meta_vars.clone env["QUERY_STRING"] = req.request_uri.query -- cgit v1.2.3