Skip to content

Instantly share code, notes, and snippets.

@starrhorne
Created January 19, 2012 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save starrhorne/1637315 to your computer and use it in GitHub Desktop.
Save starrhorne/1637315 to your computer and use it in GitHub Desktop.
require 'rack/utils'
class FlashSessionCookieMiddleware
def initialize(app, session_key = '_session_id')
@app = app
@session_key = session_key
end
def call(env)
if env['HTTP_USER_AGENT'] =~ /^(Adobe|Shockwave) Flash/
params = ::Rack::Utils.parse_query(env['QUERY_STRING'])
unless params[@session_key].nil?
env['HTTP_COOKIE'] = "#{@session_key}=#{params[@session_key]}".freeze
end
# Here's the goods
unless params['_http_accept'].nil?
env['HTTP_ACCEPT'] = "#{params['_http_accept']}".freeze
end
end
@app.call(env)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment