Sha256: 1157316d65bb12a8d1dd7bac5c3f848c922f5a113e743c7bd63f614b237873d4

Contents?: true

Size: 714 Bytes

Versions: 3

Compression:

Stored size: 714 Bytes

Contents

require 'rack'
require 'rack/utils'

module Murlsh

  # Rack middleware to set a far future expires header for urls that match
  # patterns.
  class FarFutureExpires

    def initialize(app, options={})
      @app = app
      @patterns = options[:patterns] ? [*options[:patterns]] : []
      @future = options[:future] || 'Wed, 22 Jun 2019 20:07:00 GMT'
    end

    def call(env)
      status, headers, body = @app.call(env)

      req = Rack::Request.new(env)

      headers = Rack::Utils::HeaderHash.new(headers)

      @patterns.each do |pattern|
        if pattern.match(req.path)
          headers['Expires'] = @future
          break
        end
      end

      [status, headers, body]
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
murlsh-1.2.1 lib/murlsh/far_future_expires.rb
murlsh-1.2.0 lib/murlsh/far_future_expires.rb
murlsh-1.1.0 lib/murlsh/far_future_expires.rb