Let fresh_when actually do the head(:not_modified). Cleaner and we get the filter halting for free then.
This commit is contained in:
parent
68d84e2593
commit
448e7e7c04
@ -1077,8 +1077,7 @@ def redirect_to_full_url(url, status)
|
|||||||
# Sets the etag and/or last_modified on the response and checks it against
|
# Sets the etag and/or last_modified on the response and checks it against
|
||||||
# the client request. If the request doesn't match the options provided, the
|
# the client request. If the request doesn't match the options provided, the
|
||||||
# request is considered stale and should be generated from scratch. Otherwise,
|
# request is considered stale and should be generated from scratch. Otherwise,
|
||||||
# it's fresh and we don't need to generate anything and can rely on the default
|
# it's fresh and we don't need to generate anything and a reply of "304 Not Modified" is sent.
|
||||||
# reply of "304 Not Modified".
|
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
#
|
#
|
||||||
@ -1102,9 +1101,8 @@ def fresh?(options)
|
|||||||
!stale?(options)
|
!stale?(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sets the etag, last_modified, or both such that the request can be short-circuited
|
# Sets the etag, last_modified, or both on the response and renders a
|
||||||
# with a "304 Not Modified" response instead of rendering a template when the request
|
# "304 Not Modified" response if the request is already fresh.
|
||||||
# is already fresh.
|
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
#
|
#
|
||||||
@ -1120,6 +1118,10 @@ def fresh_when(options)
|
|||||||
|
|
||||||
response.etag = options[:etag] if options[:etag]
|
response.etag = options[:etag] if options[:etag]
|
||||||
response.last_modified = options[:last_modified] if options[:last_modified]
|
response.last_modified = options[:last_modified] if options[:last_modified]
|
||||||
|
|
||||||
|
if request.fresh?(response)
|
||||||
|
head :not_modified
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sets a HTTP 1.1 Cache-Control header. Defaults to issuing a "private" instruction, so that
|
# Sets a HTTP 1.1 Cache-Control header. Defaults to issuing a "private" instruction, so that
|
||||||
@ -1208,11 +1210,7 @@ def log_processing
|
|||||||
end
|
end
|
||||||
|
|
||||||
def default_render #:nodoc:
|
def default_render #:nodoc:
|
||||||
if request.fresh?(response)
|
render
|
||||||
head :not_modified
|
|
||||||
else
|
|
||||||
render
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform_action
|
def perform_action
|
||||||
|
@ -41,9 +41,7 @@ def conditional_hello_with_bangs
|
|||||||
before_filter :handle_last_modified_and_etags, :only=>:conditional_hello_with_bangs
|
before_filter :handle_last_modified_and_etags, :only=>:conditional_hello_with_bangs
|
||||||
|
|
||||||
def handle_last_modified_and_etags
|
def handle_last_modified_and_etags
|
||||||
if fresh?(:last_modified => Time.now.utc.beginning_of_day, :etag => [ :foo, 123 ])
|
fresh_when(:last_modified => Time.now.utc.beginning_of_day, :etag => [ :foo, 123 ])
|
||||||
head :not_modified
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_hello_world
|
def render_hello_world
|
||||||
|
Loading…
Reference in New Issue
Block a user