Mercurial > libervia-web
changeset 920:8cea8bf41b03
server: new purgeSession and getSessionData helper methods
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 29 Mar 2017 19:46:27 +0200 |
parents | 7b267496da1d |
children | cf527974a0fa |
files | src/server/server.py |
diffstat | 1 files changed, 22 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/server/server.py Wed Mar 29 19:46:04 2017 +0200 +++ b/src/server/server.py Wed Mar 29 19:46:27 2017 +0200 @@ -1777,6 +1777,28 @@ # FIXME: check that no information is leaked (c.f. https://twistedmatrix.com/documents/current/web/howto/using-twistedweb.html#request-encoders) self.root.putChild(path, web_resource.EncodingResourceWrapper(resource, [server.GzipEncoderFactory()])) + ## Sessions ## + + def purgeSession(self, request): + """helper method to purge a session during request handling""" + session = request.session + if session is not None: + log.debug(_(u"session purge")) + session.expire() + # FIXME: not clean but it seems that it's the best way to reset + # session during request handling + request._secureSession = request._insecureSession = None + + def getSessionData(self, request, *args): + """helper method to retrieve session data + + @param request(server.Request): request linked to the session + @param *args(zope.interface.Interface): interface of the session to get + @return (iterator(data)): requested session data + """ + session = request.getSession() + return (iface(session) for iface in args) + ## TLS related methods ## def _TLSOptionsCheck(self):