[Twisted-web] [patch] 1/3 web2 cookies

Andrea Arcangeli andrea at cpushare.com
Wed May 17 09:53:30 CDT 2006


This allows setting and getting the cookies with web2 headers. My app
uses this new API to share the code with others. (I will probably port
my standalone web2 guard code interfaced with sql as well once I will
have the time)

diff -r 493b5c24e0f3 twisted/web2/http_headers.py
--- a/twisted/web2/http_headers.py	Tue May 16 04:57:00 2006 +0000
+++ b/twisted/web2/http_headers.py	Wed May 17 15:59:28 2006 +0200
@@ -1260,6 +1260,15 @@ class Headers(object):
     def _mutateRaise(self, *args):
         raise AttributeError("This header object is immutable as the headers have already been sent.")
 
+    def getCookie(self, name):
+        for cookie in self.getHeader('cookie', ()):
+            if cookie.name == name:
+                return cookie
+    def setCookie(self, name, *args, **kwargs):
+        set_cookies = self.getHeader('set-cookie', [])
+        set_cookies.append(Cookie(name, *args, **kwargs))
+        self.setHeader('set-cookie', set_cookies)
+
 
 """The following dicts are all mappings of header to list of operations
    to perform. The first operation should generally be 'tokenize' if the



More information about the Twisted-web mailing list