module ActionDispatch::Http::Cache::Response
def etag
def etag @etag end
def etag=(etag)
def etag=(etag) key = ActiveSupport::Cache.expand_cache_key(etag) @etag = self["ETag"] = %("#{Digest::MD5.hexdigest(key)}") end
def etag?
def etag? @etag end
def handle_conditional_get!
def handle_conditional_get! if etag? || last_modified? || !@cache_control.empty? set_conditional_cache_control! elsif nonempty_ok_response? self.etag = body if request && request.etag_matches?(etag) self.status = 304 self.body = [] end set_conditional_cache_control! else headers["Cache-Control"] = "no-cache" end end
def initialize(*)
def initialize(*) status, header, body = super @cache_control = {} @etag = self["ETag"] if cache_control = self["Cache-Control"] cache_control.split(/,\s*/).each do |segment| first, last = segment.split("=") last ||= true @cache_control[first.to_sym] = last end end end
def last_modified
def last_modified if last = headers['Last-Modified'] Time.httpdate(last) end end
def last_modified=(utc_time)
def last_modified=(utc_time) headers['Last-Modified'] = utc_time.httpdate end
def last_modified?
def last_modified? headers.include?('Last-Modified') end
def nonempty_ok_response?
def nonempty_ok_response? @status == 200 && string_body? end
def set_conditional_cache_control!
def set_conditional_cache_control! return if self["Cache-Control"].present? control = @cache_control if control.empty? headers["Cache-Control"] = DEFAULT_CACHE_CONTROL elsif @cache_control[:no_cache] headers["Cache-Control"] = "no-cache" else extras = control[:extras] max_age = control[:max_age] options = [] options << "max-age=#{max_age.to_i}" if max_age options << (control[:public] ? "public" : "private") options << "must-revalidate" if control[:must_revalidate] options.concat(extras) if extras headers["Cache-Control"] = options.join(", ") end end
def string_body?
def string_body? !@blank && @body.respond_to?(:all?) && @body.all? { |part| part.is_a?(String) } end