user1746971
user1746971

Reputation:

Stop Rack session setting a cookie for all pages

In my Sinatra app I am using rack sessions

use Rack::Session::Cookie, :secret => ENV['SECRET']

It seems to be setting a cookie for every page load, even if I am not setting anything in a session. Is there a way to change it to only set a cookie if a session is set?

Upvotes: 1

Views: 378

Answers (1)

user904990
user904990

Reputation:

Rack::Session::Cookie keeps sessions into a marshaled Ruby Hash.

Basically it is marshaling your session and persist it into cookies.

And it does not care your session is an empty Hash,
it will be marshaled and persisted into cookies anyway.

Do you really need to keep your sessions in cookies?

Perhaps use Rack::Session::Pool to keep your sessions in a memory pool?
Then it will set a cookie only once.

Upvotes: 1

Related Questions