Sha256: 8cf317960c510c6709b39b973acee90cfe193d0a519a8340da4e90e8bc8ab72c
Contents?: true
Size: 870 Bytes
Versions: 9
Compression:
Stored size: 870 Bytes
Contents
require 'uri' # app/middleware/set_cookie.rb module AppManager class SetLocalStorage def initialize(app, condition,destination_url) @app = app @condition = condition @destination_url = destination_url end def call(env) request = Rack::Request.new(env) if @condition.call(request) url = URI.parse(request.url) host = url.host discount_code = request.path.split('/')[2] rescue '' AppManager.clear_cache #clearing cache # Set a 302 response with an external URL and a cookie return [ 302, { 'Location' => "#{@destination_url}?discount_code=#{discount_code}" , 'Content-Type' => 'text/plain' }, ['Redirecting to external URL with cookie'] ] end @app.call(env) end end end
Version data entries
9 entries across 9 versions & 1 rubygems