aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/base/conditional_get.rb
diff options
context:
space:
mode:
authorYehuda Katz <wycats@gmail.com>2009-07-30 21:00:39 -0700
committerYehuda Katz <wycats@gmail.com>2009-08-02 19:39:33 -0400
commit503ce1d01ce6c8eee9818f4e76a9f880bb1a291d (patch)
treecd7e9febdd4afab332bc677c76986c3bf1481930 /actionpack/lib/action_controller/base/conditional_get.rb
parentf2a35723c8876697d5a7ebfdf329cee54d8a39ac (diff)
downloadrails-503ce1d01ce6c8eee9818f4e76a9f880bb1a291d.tar.gz
rails-503ce1d01ce6c8eee9818f4e76a9f880bb1a291d.tar.bz2
rails-503ce1d01ce6c8eee9818f4e76a9f880bb1a291d.zip
Update cache_control to be a Hash of options that is used to build the header.
* Significantly simplifies setting and modifying cache control in other areas
Diffstat (limited to 'actionpack/lib/action_controller/base/conditional_get.rb')
-rw-r--r--actionpack/lib/action_controller/base/conditional_get.rb23
1 files changed, 4 insertions, 19 deletions
diff --git a/actionpack/lib/action_controller/base/conditional_get.rb b/actionpack/lib/action_controller/base/conditional_get.rb
index d287ec4994..6d35137428 100644
--- a/actionpack/lib/action_controller/base/conditional_get.rb
+++ b/actionpack/lib/action_controller/base/conditional_get.rb
@@ -29,11 +29,7 @@ module ActionController
response.last_modified = options[:last_modified] if options[:last_modified]
if options[:public]
- cache_control = response.headers["Cache-Control"].split(",").map {|k| k.strip }
- cache_control.delete("private")
- cache_control.delete("no-cache")
- cache_control << "public"
- response.headers["Cache-Control"] = cache_control.join(', ')
+ response.cache_control[:public] = true
end
if request.fresh?(response)
@@ -107,21 +103,10 @@ module ActionController
# This method will overwrite an existing Cache-Control header.
# See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html for more possibilities.
def expires_in(seconds, options = {}) #:doc:
- cache_control = response.headers["Cache-Control"].split(",").map {|k| k.strip }
+ response.cache_control.merge!(:max_age => seconds, :public => options.delete(:public))
+ options.delete(:private)
- cache_control << "max-age=#{seconds}"
- cache_control.delete("no-cache")
- if options[:public]
- cache_control.delete("private")
- cache_control << "public"
- else
- cache_control << "private"
- end
-
- # This allows for additional headers to be passed through like 'max-stale' => 5.hours
- cache_control += options.symbolize_keys.reject{|k,v| k == :public || k == :private }.map{ |k,v| v == true ? k.to_s : "#{k.to_s}=#{v.to_s}"}
-
- response.headers["Cache-Control"] = cache_control.join(', ')
+ response.cache_control[:extras] = options.map {|k,v| "#{k}=#{v}"}
end
# Sets a HTTP 1.1 Cache-Control header of "no-cache" so no caching should occur by the browser or