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
Session::CookieA session is able to store the same information that would ordinarily be sent via a post request in a Session Cookie. This is known as session based cookie management and Rack has different ways to implement cookies.
A session is a way for a web application to set a cookie that persists an identifier across multiple HTTP requests, and then relate these requests to each other: If you've signed in before the web application will be able to know that you're still the same user you've identified as a couple requests earlier.
HTTP cookies, or internet cookies, are built specifically for Internet web browsers to track, personalize, and save information about each user's session. A “session” just refers to the time you spend on a site. Cookies are created to identify you when you visit a new website.
Cookies are read and written through ActionController#cookies. The cookies being read are the ones received along with the request, the cookies being written will be sent out with the response. Reading a cookie does not get the cookie object itself back, just the value it holds.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With