Sha256: c778c4357019dbd1956e4b18a592678c8c63b7ce023d8d62c8fd86b02223c7c4

Contents?: true

Size: 696 Bytes

Versions: 2

Compression:

Stored size: 696 Bytes

Contents

module CacheableFlash
  class Middleware
    require 'cacheable_flash/config'
    require 'cacheable_flash/cookie_flash'
    include CacheableFlash::CookieFlash
    FLASH_HASH_KEY = "action_dispatch.request.flash_hash".freeze

    def initialize(app)
      @app = app
    end

    def call(env)
      status, headers, body = @app.call(env)
      env_flash = env[FLASH_HASH_KEY]

      if env_flash
        domain = CacheableFlash::Config.config[:domain]
        cookies = Rack::Request.new(env).cookies
        Rack::Utils.set_cookie_header!(headers, "flash", :value => cookie_flash(env_flash, cookies), :path => "/", :domain => domain)
      end

      [status, headers, body]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cacheable_flash-1.0.0 lib/cacheable_flash/middleware.rb
cacheable_flash-0.3.4 lib/cacheable_flash/middleware.rb