comparison src/server/server.py @ 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
comparison
equal deleted inserted replaced
919:7b267496da1d 920:8cea8bf41b03
1775 def putChild(self, path, resource): 1775 def putChild(self, path, resource):
1776 """Add a child to the root resource""" 1776 """Add a child to the root resource"""
1777 # FIXME: check that no information is leaked (c.f. https://twistedmatrix.com/documents/current/web/howto/using-twistedweb.html#request-encoders) 1777 # FIXME: check that no information is leaked (c.f. https://twistedmatrix.com/documents/current/web/howto/using-twistedweb.html#request-encoders)
1778 self.root.putChild(path, web_resource.EncodingResourceWrapper(resource, [server.GzipEncoderFactory()])) 1778 self.root.putChild(path, web_resource.EncodingResourceWrapper(resource, [server.GzipEncoderFactory()]))
1779 1779
1780 ## Sessions ##
1781
1782 def purgeSession(self, request):
1783 """helper method to purge a session during request handling"""
1784 session = request.session
1785 if session is not None:
1786 log.debug(_(u"session purge"))
1787 session.expire()
1788 # FIXME: not clean but it seems that it's the best way to reset
1789 # session during request handling
1790 request._secureSession = request._insecureSession = None
1791
1792 def getSessionData(self, request, *args):
1793 """helper method to retrieve session data
1794
1795 @param request(server.Request): request linked to the session
1796 @param *args(zope.interface.Interface): interface of the session to get
1797 @return (iterator(data)): requested session data
1798 """
1799 session = request.getSession()
1800 return (iface(session) for iface in args)
1801
1780 ## TLS related methods ## 1802 ## TLS related methods ##
1781 1803
1782 def _TLSOptionsCheck(self): 1804 def _TLSOptionsCheck(self):
1783 """Check options coherence if TLS is activated, and update missing values 1805 """Check options coherence if TLS is activated, and update missing values
1784 1806