Diez,
Your post pointed me in the right direction. I tried your idea, but
the SessionMiddleware is needed (they call it core middleware for a
reason). Other code expects it to be there, so it can't be just
removed. Instead, I went one level deeper and modified the
SessionMiddleware itself to NOT set a cookie. I didn't want to modify
the beaker package itself of course (bad practice). I could in theory
subclass the beaker SessionMiddleware and then sublass AppConfig to
add my custom SessionMiddleware, but it becomes a little cumbersome.
So, I ended up just replacing the __call__the method of the original
beaker SessionMiddleware in my AppCfg.py file. The commented lines
bellow are the lines that set the cookie:
### Start code #####
from beaker.middleware import SessionMiddleware
from beaker.session import SessionObject
def custom_session_middleware__call__(self, environ, start_response):
session = SessionObject(environ, **self.options)
if environ.get('paste.registry'):
if environ['paste.registry'].reglist:
environ['paste.registry'].register(self.session, session)
environ[self.environ_key] = session
environ['beaker.get_session'] = self._get_session
def session_start_response(status, headers, exc_info = None):
#if session.accessed():
# session.persist()
# if session.__dict__['_headers']['set_cookie']:
# cookie = session.__dict__['_headers']['cookie_out']
# if cookie:
# headers.append(('Set-cookie', cookie))
return start_response(status, headers, exc_info)
return self.wrap_app(environ, session_start_response)
SessionMiddleware.__call__ = custom_session_middleware__call__
### End code #####
Thanks, Karl
On Jul 6, 2:54 am, "Diez B. Roggisch" <de...@web.de> wrote:
> On Friday 03 July 2009 17:51:33 Carl wrote:
> > Hi,
> > Can someone explain how beaker is used in TG2? I see in the Pylons
> > docs that it can be used to persist values across calls via cookies.
> > In my app it is inappropriate. I don't use it in my controller
> > methods, but beaker still sets a cookie (beaker.session.id).
> > Can I turn it off via configuration or some other way?
> Not directly via config, no.
> What you can do is to subclass AppConfig in
> myproject.config.app_cfg
> and override the
> def add_core_middleware(self, app):
> """Add support for routes dispatch, sessions, and caching."""
> app = RoutesMiddleware(app, config['routes.map'])
> app = SessionMiddleware(app, config)
> app = CacheMiddleware(app, config)
> return app
> method with this:
> def add_core_middleware(self, app):
> """Add support for routes dispatch, sessions, and caching."""
> app = RoutesMiddleware(app, config['routes.map'])
> return app
> This is untested - but it should rid you of beaker.
> Diez