机架会话Cookie和Sinatra - 设置和访问数据 [英] Rack Session Cookie and Sinatra - setting and accessing data
问题描述
我使用Rack Session Pool,但是我的用户会将一个网络服务器线程踢到另一个线程上,使会话数据过期。我开始玩弄只是启用:Sinatra中的会话,但是我无法使用,因为我有多个应用程序使用Sinatra(相同的键,似乎使用 - 不确定这是因为它是相同的主机或不) p>
因为我的应用程序会相互破坏,我现在正在尝试Rack Session Cookie并设置变量(与enable:sessions相同,但您可以设置变量) p>
伟大的作品!但现在我不能访问会话数据的方式,我使用它,在Rack会话池和启用:会话
session [ :user] = nick
puts session [:user]
问题是为什么我可以访问session [:user]在Pool和Sinatra enable:sessions,但不是在Rack Session Cookie中的会话数据?我缺少什么吗?我所做的全部在下面
config.ru
:: Session :: Cookie,:key => 'key',
:domain => localhost,
:path => '/',
:expire_after => 14400,#以秒为单位
:secret => 'secret'
编辑:
一些更多的测试,发现它实际上把它放在会话变量,但是一旦它移动到一个新的方法或重定向会话变量似乎被删除(这个cookie真的大于4KBs?!) - 它不能
这是我做了什么来解决这个问题:
使用Rack :: Session :: Cookie,:key => 'my_app_key',
:path => '/',
:expire_after => 14400,#以秒为单位
:secret => 'secret_stuff'
你看到与上述不同吗? - 没有域,如果我让Rack :: Session :: Cookie指定域或浏览器(无论谁做的),我没有在mutliple Sinatra / Rack应用程序之间的错误...
I was using Rack Session Pool, however my users would get kicked off one webserver thread onto another making the session data expire. I started toying around with just enable :sessions in Sinatra, however I am unable to use that because I have mutliple apps using Sinatra (same key it appears to be using - not sure if this is because its the same host or not)
So since my apps would break each other, I now am trying Rack Session Cookie and setting the variables (same thing as enable :sessions, but you can set the variables)
Great so that works! But now I cannot access the session data the way I was using it, in Rack Session Pool and in enable: sessions
session[:user] = nick
puts session[:user]
you get the idea...
Question is why can I access session data with session[:user] in Pool and Sinatra enable :sessions, but not in Rack Session Cookie? Am I missing anything? All I am doing is below
config.ru
use Rack::Session::Cookie, :key => 'key',
:domain => "localhost",
:path => '/',
:expire_after => 14400, # In seconds
:secret => 'secret'
EDIT:
Did some more testing and found that it's actually putting it in the session variable, however as soon as it moves to a new method or redirection the session variable appears to be dropped (is this cookie really larger than 4KBs?!) - it can't be because enable :sessions works just fine
Here's what I did to fix this problem:
use Rack::Session::Cookie, :key => 'my_app_key',
:path => '/',
:expire_after => 14400, # In seconds
:secret => 'secret_stuff'
Do you see the difference from the above? - No Domain, if I let Rack::Session::Cookie specify the domain or the browser (whoever does it), I have no errors between mutliple Sinatra/Rack apps...
这篇关于机架会话Cookie和Sinatra - 设置和访问数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!