Module: Olelo::HttpHelper
Instance Method Summary collapse
-
#cache_control(options) ⇒ Object
Cache control for page.
Methods included from Util
#check, #decode64, #deep_copy, #encode64, #escape, #escape_html, #escape_javascript, included, #md5, #no_cache?, #sha256, #titlecase, #truncate, #unescape, #unescape_backslash, #unescape_html, #valid_xml_chars?
Instance Method Details
#cache_control(options) ⇒ Object
Cache control for page
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/olelo/helper.rb', line 227 def cache_control() return if !Config['production'] if [:no_cache] response.headers.delete('ETag') response.headers.delete('Last-Modified') response.headers.delete('Cache-Control') return end last_modified = .delete(:last_modified) modified_since = env['HTTP_IF_MODIFIED_SINCE'] last_modified = last_modified.try(:to_time) || last_modified last_modified = last_modified.try(:httpdate) || last_modified if User.logged_in? # Always private mode if user is logged in [:private] = true # Special etag for authenticated user [:etag] = "#{User.current.name}-#{[:etag]}" if [:etag] end if [:etag] value = '"%s"' % .delete(:etag) response['ETag'] = value.to_s response['Last-Modified'] = last_modified if last_modified if = env['HTTP_IF_NONE_MATCH'] = .split(/\s*,\s*/) # Etag is matching and modification date matches (HTTP Spec §14.26) halt :not_modified if (.include?(value) || .include?('*')) && (!last_modified || last_modified == modified_since) end elsif last_modified # If-Modified-Since is only processed if no etag supplied. # If the etag match failed the If-Modified-Since has to be ignored (HTTP Spec §14.26) response['Last-Modified'] = last_modified halt :not_modified if last_modified == modified_since end [:public] = ![:private] [:max_age] ||= 0 [:must_revalidate] ||= true if !.include?(:must_revalidate) response['Cache-Control'] = .map do |k, v| if v == true k.to_s.tr('_', '-') elsif v v = 31536000 if v.to_s == 'static' "#{k.to_s.tr('_', '-')}=#{v}" end end.compact.join(', ') end |