Ace - cheers!<br><br><div class="gmail_quote">On Mon, Nov 2, 2009 at 3:13 PM, Magnus Holm <span dir="ltr">&lt;<a href="mailto:judofyr@gmail.com">judofyr@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Okay, I think we&#39;re actually fine by setting :path =&gt; &quot;/&quot; by default.<br>
If you want anything different, you should use &quot;use<br>
Rack::Session::Cookie&quot; yourself.<br>
<br>
//Magnus Holm<br>
<br>
<br>
<br>
On Mon, Oct 19, 2009 at 19:14, Jonathan Hickford<br>
<div><div></div><div class="h5">&lt;<a href="mailto:jonathan.hickford%2Bcamping@gmail.com">jonathan.hickford+camping@gmail.com</a>&gt; wrote:<br>
&gt; Hi,<br>
&gt;<br>
&gt; I&#39;d be inclined to agree with the middleware approach too, especially<br>
&gt; if it&#39;s pre 2.0 release and that change can be made along side other<br>
&gt; 1.5 -&gt; 2.0 changes<br>
&gt;<br>
&gt; Jon<br>
&gt;<br>
&gt;&gt; On Sun, Oct 18, 2009 at 9:31 PM, Magnus Holm &lt;<a href="mailto:judofyr@gmail.com">judofyr@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt; Wow, great catch! This is definitely a bug. I guess this should go to<br>
&gt;&gt;&gt; GitHub issues, yes.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; This is actually an issue where Camping and Rack::Session::Cookie fight:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; At the first request, sessions.state is set in ::Cookie after Camping<br>
&gt;&gt;&gt; has done its magic.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; At the second request, Camping loads @state from @env[&#39;rack.state&#39;],<br>
&gt;&gt;&gt; the app changes the session, but @cookie[&#39;sessions.state&#39;] stays<br>
&gt;&gt;&gt; intact. Camping&#39;s #to_a then sets the cookies again in the response:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;      @cookies.each do |k, v|<br>
&gt;&gt;&gt;        v = {:value =&gt; v, :path =&gt; self / &quot;/&quot;} if String === v<br>
&gt;&gt;&gt;        r.set_cookie(k, v)<br>
&gt;&gt;&gt;      end<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Which means that it sets a sessions.state-cookie at /sessions/. Then<br>
&gt;&gt;&gt; ::Cookies kicks in and figures out that the sessions have changed and<br>
&gt;&gt;&gt; sets a new cookie, but this time at /. (This also has the effect that<br>
&gt;&gt;&gt; Camping copies all the cookies at / into /sessions/)<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; At the third request, Rack chooses cookies &quot;such that those with more<br>
&gt;&gt;&gt; specific Path attributes precede those with less specific&quot;, and the<br>
&gt;&gt;&gt; cookie at /sessions/ wins.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Your fix won&#39;t unfornately work because @root is only available inside<br>
&gt;&gt;&gt; a request/controller.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I think we need to do two things:<br>
&gt;&gt;&gt; * Make sure Camping only sets cookies when they&#39;ve changed.<br>
&gt;&gt;&gt; * Figure out a way to set :path to SCRIPT_NAME. If so, this should<br>
&gt;&gt;&gt; only be an option, as you might also want to mount two apps and have<br>
&gt;&gt;&gt; them share the sessions (aka :path =&gt; &#39;/&#39;).<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I&#39;m not quite sure how we should add that option, though. We could<br>
&gt;&gt;&gt; switch Camping::Session to be a middleware, but this means all apps<br>
&gt;&gt;&gt; will have to change &quot;include Camping::Session&quot; to &quot;use<br>
&gt;&gt;&gt; Camping::Session&quot;. It&#39;s maybe not such a big deal? We should at least<br>
&gt;&gt;&gt; do these kind of changes *before* the release of 2.0.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Some examples:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; # Middleware<br>
&gt;&gt;&gt; use Camping::Session, :secret =&gt; &quot;foo&quot;, :shared =&gt; true<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; # Subclass<br>
&gt;&gt;&gt; include Camping::Session::Shared<br>
&gt;&gt;&gt; secret &quot;foo&quot;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; # New method<br>
&gt;&gt;&gt; include Camping::Session<br>
&gt;&gt;&gt; secret &quot;foo&quot;<br>
&gt;&gt;&gt; shared_cookie!<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; # Merge #secret and #shared_cookie! together<br>
&gt;&gt;&gt; include Camping::Session<br>
&gt;&gt;&gt; session_options :secret =&gt; &quot;foo&quot;, :shared =&gt; true<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I think I actually prefer the middleware-version. It&#39;s short and<br>
&gt;&gt;&gt; concise and can be extended with more options if needed.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; What do you think?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; //Magnus Holm<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On Sun, Oct 18, 2009 at 19:59, Jonathan Hickford<br>
&gt;&gt;&gt; &lt;<a href="mailto:jonathan.hickford%2Bcamping@gmail.com">jonathan.hickford+camping@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt;&gt; Hi all,<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Not sure where best to raise this (github issues?) but I&#39;m seeing an<br>
&gt;&gt;&gt;&gt; issue with the cookie sessions in camping 2.0 using rack.  If I mount<br>
&gt;&gt;&gt;&gt; an app such as the example blog or the sessions test app at any url<br>
&gt;&gt;&gt;&gt; that is not the root session information is lost in some cases.  Same<br>
&gt;&gt;&gt;&gt; thing happens if I use the built in Camping server.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; For example if I mount the blog app using rackup at &#39;/blog&#39; I&#39;m unable<br>
&gt;&gt;&gt;&gt; to log in.  If I mount the sessions test app the information added on<br>
&gt;&gt;&gt;&gt; the second page is lost when it reaches page three.  Looking at the<br>
&gt;&gt;&gt;&gt; cookies in the browser I can see two state cookies set with the paths<br>
&gt;&gt;&gt;&gt; &#39;/&#39; and &#39;/blog/&#39;.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; I&#39;m guessing this is to do with Rack::Session::Cookie in session.rb,<br>
&gt;&gt;&gt;&gt; which will default to use :path =&gt; &#39;/&#39; in all cases.  If I explicitly<br>
&gt;&gt;&gt;&gt; add :path =&gt; &#39;/blog/&#39; there it starts working as expected.  Some more<br>
&gt;&gt;&gt;&gt; detailed outputs here (this will run from /test)<br>
&gt;&gt;&gt;&gt; <a href="http://pastebin.com/m6c13a4aa" target="_blank">http://pastebin.com/m6c13a4aa</a><br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Is that me doing something crazy there (I&#39;m not expert!) or is that a<br>
&gt;&gt;&gt;&gt; bug?  If that&#39;s an issue I think the below change to session.rb fixes<br>
&gt;&gt;&gt;&gt; it, passing in the apps @root into the path Rack&#39;s session cookie<br>
&gt;&gt;&gt;&gt; middleware.  I can push that somewhere if we reckon that&#39;s a fix?<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; - app.use Rack::Session::Cookie, :key =&gt; key, :secret =&gt; secret<br>
&gt;&gt;&gt;&gt; + app.use Rack::Session::Cookie, :key =&gt; key, :secret =&gt; secret, :path =&gt; @root<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Regards,<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Jon<br>
&gt;&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt;&gt; Camping-list mailing list<br>
&gt;&gt;&gt;&gt; <a href="mailto:Camping-list@rubyforge.org">Camping-list@rubyforge.org</a><br>
&gt;&gt;&gt;&gt; <a href="http://rubyforge.org/mailman/listinfo/camping-list" target="_blank">http://rubyforge.org/mailman/listinfo/camping-list</a><br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt; Camping-list mailing list<br>
&gt;&gt;&gt; <a href="mailto:Camping-list@rubyforge.org">Camping-list@rubyforge.org</a><br>
&gt;&gt;&gt; <a href="http://rubyforge.org/mailman/listinfo/camping-list" target="_blank">http://rubyforge.org/mailman/listinfo/camping-list</a><br>
&gt;&gt;<br>
&gt; _______________________________________________<br>
&gt; Camping-list mailing list<br>
&gt; <a href="mailto:Camping-list@rubyforge.org">Camping-list@rubyforge.org</a><br>
&gt; <a href="http://rubyforge.org/mailman/listinfo/camping-list" target="_blank">http://rubyforge.org/mailman/listinfo/camping-list</a><br>
&gt;<br>
_______________________________________________<br>
Camping-list mailing list<br>
<a href="mailto:Camping-list@rubyforge.org">Camping-list@rubyforge.org</a><br>
<a href="http://rubyforge.org/mailman/listinfo/camping-list" target="_blank">http://rubyforge.org/mailman/listinfo/camping-list</a></div></div></blockquote></div><br>