mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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
This commit is contained in:
parent
69d0f50206
commit
e4f07888ce
3 changed files with 20 additions and 8 deletions
|
@ -90,11 +90,7 @@ module ActionController #:nodoc:
|
||||||
|
|
||||||
private
|
private
|
||||||
def page_cache_path(path)
|
def page_cache_path(path)
|
||||||
if path[-1,1] == '/'
|
page_cache_directory + path + ".html"
|
||||||
page_cache_directory + path + '/index'
|
|
||||||
else
|
|
||||||
page_cache_directory + path
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -115,13 +111,14 @@ module ActionController #:nodoc:
|
||||||
# If no options are provided, the current +options+ for this action is used. Example:
|
# If no options are provided, the current +options+ for this action is used. Example:
|
||||||
# cache_page "I'm the cached content", :controller => "lists", :action => "show"
|
# cache_page "I'm the cached content", :controller => "lists", :action => "show"
|
||||||
def cache_page(content = nil, options = {})
|
def cache_page(content = nil, options = {})
|
||||||
|
logger.info "Cached page: #{options.inspect} || #{caching_allowed}"
|
||||||
return unless perform_caching && caching_allowed
|
return unless perform_caching && caching_allowed
|
||||||
self.class.cache_page(content || @response.body, url_for(options.merge({ :only_path => true })))
|
self.class.cache_page(content || @response.body, url_for(options.merge({ :only_path => true })))
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def caching_allowed
|
def caching_allowed
|
||||||
!@request.post? && (@request.parameters.reject { |k, v| %w( id action controller ).include?(k) }).empty?
|
!@request.post?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,9 @@ module ActionController #:nodoc:
|
||||||
base.helper do
|
base.helper do
|
||||||
def render_component(options)
|
def render_component(options)
|
||||||
@controller.logger.info("Start rendering component (#{options.inspect}): ")
|
@controller.logger.info("Start rendering component (#{options.inspect}): ")
|
||||||
@controller.send(:component_response, options).body
|
result = @controller.send(:component_response, options).body
|
||||||
@controller.logger.info("\n\nEnd of component rendering")
|
@controller.logger.info("\n\nEnd of component rendering")
|
||||||
|
return result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -15,8 +16,9 @@ module ActionController #:nodoc:
|
||||||
def render_component(options = {}) #:doc:
|
def render_component(options = {}) #:doc:
|
||||||
response = component_response(options)
|
response = component_response(options)
|
||||||
logger.info "Rendering component (#{options.inspect}): "
|
logger.info "Rendering component (#{options.inspect}): "
|
||||||
render_text(response.body, response.headers["Status"])
|
result = render_text(response.body, response.headers["Status"])
|
||||||
logger.info("\n\nEnd of component rendering")
|
logger.info("\n\nEnd of component rendering")
|
||||||
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -6,6 +6,7 @@ require 'stringio'
|
||||||
|
|
||||||
include WEBrick
|
include WEBrick
|
||||||
|
|
||||||
|
|
||||||
class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet
|
class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet
|
||||||
REQUEST_MUTEX = Mutex.new
|
REQUEST_MUTEX = Mutex.new
|
||||||
|
|
||||||
|
@ -42,16 +43,28 @@ class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet
|
||||||
|
|
||||||
def handle_file(req, res)
|
def handle_file(req, res)
|
||||||
begin
|
begin
|
||||||
|
add_dot_html(req)
|
||||||
@file_handler.send(:do_GET, req, res)
|
@file_handler.send(:do_GET, req, res)
|
||||||
|
remove_dot_html(req)
|
||||||
return true
|
return true
|
||||||
rescue HTTPStatus::PartialContent, HTTPStatus::NotModified => err
|
rescue HTTPStatus::PartialContent, HTTPStatus::NotModified => err
|
||||||
res.set_error(err)
|
res.set_error(err)
|
||||||
return true
|
return true
|
||||||
rescue => err
|
rescue => err
|
||||||
return false
|
return false
|
||||||
|
ensure
|
||||||
|
remove_dot_html(req)
|
||||||
end
|
end
|
||||||
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)
|
def handle_dispatch(req, res, origin = nil)
|
||||||
env = req.meta_vars.clone
|
env = req.meta_vars.clone
|
||||||
env["QUERY_STRING"] = req.request_uri.query
|
env["QUERY_STRING"] = req.request_uri.query
|
||||||
|
|
Loading…
Reference in a new issue