Sha256: 5d5f59001827d7a582af6a14874df4da6f64e98443a9521162c94ab5fa334816

Contents?: true

Size: 626 Bytes

Versions: 9

Compression:

Stored size: 626 Bytes

Contents

module Spontaneous::Rack
  class CacheableFile < ::Rack::File
    include Constants

    TEN_YEARS = 10*365.25*24*3600
    MAX_AGE =  "max-age=#{TEN_YEARS}, public".freeze

    def initialize(file_root)
      super(file_root)
    end

    def call(env)
      status, headers, body = super
      [status, caching_headers(headers), body]
    end

    # Send a far future Expires header and make sure that
    # the cache control is public
    def caching_headers(headers)
      headers.update({
        HTTP_CACHE_CONTROL => MAX_AGE,
        HTTP_EXPIRES => (Time.now.advance(:years => 10)).httpdate
      })
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta10 lib/spontaneous/rack/cacheable_file.rb
spontaneous-0.2.0.beta9 lib/spontaneous/rack/cacheable_file.rb
spontaneous-0.2.0.beta8 lib/spontaneous/rack/cacheable_file.rb
spontaneous-0.2.0.beta7 lib/spontaneous/rack/cacheable_file.rb
spontaneous-0.2.0.beta6 lib/spontaneous/rack/cacheable_file.rb
spontaneous-0.2.0.beta5 lib/spontaneous/rack/cacheable_file.rb
spontaneous-0.2.0.beta4 lib/spontaneous/rack/cacheable_file.rb
spontaneous-0.2.0.beta3 lib/spontaneous/rack/cacheable_file.rb
spontaneous-0.2.0.beta2 lib/spontaneous/rack/cacheable_file.rb