Daniel Bryan
2012-Jan-02 11:10 UTC
Is it possible to read session data from Camping::Session in a middleware?
I''m trying to implement some simple middleware that will have behaviour based on session data.>From looking at the source for Camping::Session and Rack::Session, I thought I''d just be able to put my own middleware between Camping::Session and my app. I tried doing it the same way that Camping::Session works - by including a module in my app - but if I inspect the environment in there, it''s still encrypted.Has anyone else tried something like this? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/camping-list/attachments/20120102/b5125a5a/attachment.html>
Jenna Fox
2012-Jan-02 11:20 UTC
Is it possible to read session data from Camping::Session in a middleware?
If you look in to the Rack docs, you''ll find more info on how to chain middleware together. Camping provides some friendly shortcuts to that, but ''including a module'' is not how that''s supposed to work, is my understanding. Essentially Rack middleware work by creating an object which responds to a ''call'' method, and then calls the call on another thing, creating a chain of ''call'' method calls. Call call? Call. Call call call. But yes, if you play with that more directly, you can clearly describe which objects feed in to each other, and have the session middleware at a more outer layer than your own middleware. Usually this ends up looking like: run OuterMostMiddleware.new(MiddleMiddleware.new(InnerMiddleware.new(SomeCampingApp))) Each layer wraps around the outside of the next, so the message from a web request travels in left to right along this line, then the response travels back right to left as each ''call'' method on the middleware objects finish their work and return to the next layer leftward. ? Jenna Fox On Monday, 2 January 2012 at 10:10 PM, Daniel Bryan wrote:> I''m trying to implement some simple middleware that will have behaviour based on session data. > > From looking at the source for Camping::Session and Rack::Session, I thought I''d just be able to put my own middleware between Camping::Session and my app. I tried doing it the same way that Camping::Session works - by including a module in my app - but if I inspect the environment in there, it''s still encrypted. > > Has anyone else tried something like this? > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org (mailto:Camping-list at rubyforge.org) > http://rubyforge.org/mailman/listinfo/camping-list > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/camping-list/attachments/20120102/a1f2f709/attachment.html>
Daniel Bryan
2012-Jan-02 11:39 UTC
Is it possible to read session data from Camping::Session in a middleware?
Ah, thanks. I thought that the order of calling ''use'' would explicitly describe the order. This was my main problem - since Camping''s doing a bit of a hack to neatly slot the middleware in without people needing a rackup file or whatever, it''s a bit unclear on how to get stuff in the right order. I ended up just using Rack::Session::Cookie in my rackup file, and removing ''include Camping::Session'' from my Camping app. On Monday, 2 January 2012 at 10:20 PM, Jenna Fox wrote:> If you look in to the Rack docs, you''ll find more info on how to chain middleware together. Camping provides some friendly shortcuts to that, but ''including a module'' is not how that''s supposed to work, is my understanding. Essentially Rack middleware work by creating an object which responds to a ''call'' method, and then calls the call on another thing, creating a chain of ''call'' method calls. Call call? Call. > > Call call call. > > But yes, if you play with that more directly, you can clearly describe which objects feed in to each other, and have the session middleware at a more outer layer than your own middleware. Usually this ends up looking like: > > run OuterMostMiddleware.new(MiddleMiddleware.new(InnerMiddleware.new(SomeCampingApp))) > > Each layer wraps around the outside of the next, so the message from a web request travels in left to right along this line, then the response travels back right to left as each ''call'' method on the middleware objects finish their work and return to the next layer leftward. > > > ? > Jenna Fox > > > On Monday, 2 January 2012 at 10:10 PM, Daniel Bryan wrote: > > > I''m trying to implement some simple middleware that will have behaviour based on session data. > > > > From looking at the source for Camping::Session and Rack::Session, I thought I''d just be able to put my own middleware between Camping::Session and my app. I tried doing it the same way that Camping::Session works - by including a module in my app - but if I inspect the environment in there, it''s still encrypted. > > > > Has anyone else tried something like this? > > _______________________________________________ > > Camping-list mailing list > > Camping-list at rubyforge.org (mailto:Camping-list at rubyforge.org) > > http://rubyforge.org/mailman/listinfo/camping-list > > > > > > > > > _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org (mailto:Camping-list at rubyforge.org) > http://rubyforge.org/mailman/listinfo/camping-list > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/camping-list/attachments/20120102/e7f29152/attachment-0001.html>
Magnus Holm
2012-Jan-02 13:33 UTC
Is it possible to read session data from Camping::Session in a middleware?
On Mon, Jan 2, 2012 at 12:39, Daniel Bryan <danbryan at gmail.com> wrote:> Ah, thanks. > > I thought that the order of calling ''use'' would explicitly describe the > order. This was my main problem - since Camping''s doing a bit of a hack to > neatly slot the middleware in without people needing a rackup file or > whatever, it''s a bit unclear on how to get stuff in the right order.Yeah, it''s in reverse order: module App use Foo use Bar end is the same as: Bar.new(Foo.new(App))> I ended up just using Rack::Session::Cookie in my rackup file, and removing > ''include Camping::Session'' from my Camping app.