Skip to content

Instantly share code, notes, and snippets.

@godfat
Created June 3, 2015 17:56
Show Gist options
  • Save godfat/25f79486d35f28cf12e9 to your computer and use it in GitHub Desktop.
Save godfat/25f79486d35f28cf12e9 to your computer and use it in GitHub Desktop.
class MigrateCookie < Struct.new(:app)
def call env
cookies = Rack::Utils.parse_query(env['HTTP_COOKIE'], ';,')
case cookies['_session_id']
when Array
status, headers, body = app.call(env)
headers['Set-Cookie'] =
"#{headers['Set-Cookie']}\n#{expire_old_session}"
[status, headers, body]
else
app.call(env)
end
end
private
def expire_old_session
"_session_id=deleted; path=/;" \
" expires=Thu, Jan 01 1970 00:00:00 UTC; HttpOnly"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment