Created
February 24, 2010 10:42
-
-
Save DAddYE/313322 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rack/utils' | |
## | |
# FlashMiddleware help you passing your session in the URI, when it should be in the cookie. | |
# | |
# This code it's only performed when: | |
# | |
# env['HTTP_USER_AGENT'] =~ /^(Adobe|Shockwave) Flash/ | |
# | |
# ==== Usage | |
# | |
# use FlashMiddleware, session_id | |
# | |
class FlashMiddleware | |
def initialize(app, session_key = 'session_id') | |
@app = app | |
@session_key = session_key.to_s | |
end | |
def call(env) | |
if env['HTTP_USER_AGENT'] =~ /^(Adobe|Shockwave) Flash/ | |
params = ::Rack::Request.new(env).params | |
env['rack.session'] ||= {} | |
env['rack.session'][@session_key.to_sym] = params[@session_key] if params[@session_key].present? | |
end | |
@app.call(env) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment