Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #2503 -- Fixed HttpResponse.delete_cookie() to work properly. I…

…t now takes path and domain as optional keyword arguments.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3545 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 925c711cf75072526ced0ae8f18d561dca612092 1 parent 2c370e1
Adrian Holovaty authored August 09, 2006
15  django/http/__init__.py
@@ -38,7 +38,7 @@ def has_key(self, key):
38 38
 
39 39
     def get_full_path(self):
40 40
         return ''
41  
-        
  41
+
42 42
     def is_secure(self):
43 43
         return os.environ.get("HTTPS") == "on"
44 44
 
@@ -203,11 +203,14 @@ def set_cookie(self, key, value='', max_age=None, expires=None, path='/', domain
203 203
             if val is not None:
204 204
                 self.cookies[key][var.replace('_', '-')] = val
205 205
 
206  
-    def delete_cookie(self, key):
207  
-        try:
208  
-            self.cookies[key]['max_age'] = 0
209  
-        except KeyError:
210  
-            pass
  206
+    def delete_cookie(self, key, path='/', domain=None):
  207
+        self.cookies[key] = ''
  208
+        if path is not None:
  209
+            self.cookies[key]['path'] = path
  210
+        if domain is not None:
  211
+            self.cookies[key]['domain'] = path
  212
+        self.cookies[key]['expires'] = 0
  213
+        self.cookies[key]['max-age'] = 0
211 214
 
212 215
     def _get_content(self):
213 216
         content = ''.join(self._iterator)
8  docs/request_response.txt
@@ -149,7 +149,7 @@ Methods
149 149
    Returns the ``path``, plus an appended query string, if applicable.
150 150
 
151 151
    Example: ``"/music/bands/the_beatles/?print=true"``
152  
-    
  152
+
153 153
 ``is_secure()``
154 154
    Returns ``True`` if the request is secure; that is, if it was made with
155 155
    HTTPS.
@@ -380,10 +380,14 @@ Methods
380 380
 
381 381
     .. _`cookie Morsel`: http://www.python.org/doc/current/lib/morsel-objects.html
382 382
 
383  
-``delete_cookie(key)``
  383
+``delete_cookie(key, path='/', domain=None)``
384 384
     Deletes the cookie with the given key. Fails silently if the key doesn't
385 385
     exist.
386 386
 
  387
+    The ``path`` and ``domain`` arguments are new in the Django development version.
  388
+    Due to the way cookies work, ``path`` and ``domain`` should be the same
  389
+    values you used in ``set_cookie()`` -- otherwise the cookie may not be deleted.
  390
+
387 391
 ``content``
388 392
     Returns the content as a Python string, encoding it from a Unicode object
389 393
     if necessary. Note this is a property, not a method, so use ``r.content``

0 notes on commit 925c711

Please sign in to comment.
Something went wrong with that request. Please try again.