Fixed action_cache Plugin
The action_cache plugin had Conditional GET (If-Modified-Since) support. I added ETag (If-None-Match) support.
This commit is contained in:
parent
c67cfbc52d
commit
5db9b7d3ea
1 changed files with 6 additions and 1 deletions
|
@ -134,6 +134,7 @@ module ActionController
|
|||
controller.response.headers['Cache-Control'] == 'no-cache'
|
||||
controller.response.headers['Cache-Control'] = "max-age=#{controller.response.time_to_live}"
|
||||
end
|
||||
controller.response.headers['Etag'] = "\"#{MD5.new(controller.response.body).to_s}\""
|
||||
controller.response.headers['Last-Modified'] ||= Time.now.httpdate
|
||||
end
|
||||
|
||||
|
@ -145,10 +146,14 @@ module ActionController
|
|||
|
||||
def send_not_modified(controller)
|
||||
controller.logger.info "Send Not Modified"
|
||||
controller.response.headers['Etag'] = "\"#{MD5.new(fragment_body(controller)).to_s}\""
|
||||
controller.render(:text => "", :status => 304)
|
||||
end
|
||||
|
||||
def client_has_latest?(cache_entry, controller)
|
||||
requestEtag = controller.request.env['HTTP_IF_NONE_MATCH'] rescue nil
|
||||
responseEtag = cache_entry.headers['Etag'] rescue nil
|
||||
return true if (requestEtag and responseEtag and requestEtag == responseEtag)
|
||||
requestTime = Time.rfc2822(controller.request.env["HTTP_IF_MODIFIED_SINCE"]) rescue nil
|
||||
responseTime = Time.rfc2822(cache_entry.headers['Last-Modified']) rescue nil
|
||||
return (requestTime and responseTime and responseTime <= requestTime)
|
||||
|
@ -229,4 +234,4 @@ module ActionController
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue