summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-08-09 15:40:24 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-08-09 15:40:24 +0000
commit925c711cf75072526ced0ae8f18d561dca612092 (patch)
tree9461d6434255e8d099047b7216abe81f3491691b
parent2c370e1a08d3d7bac17d8cfe8c909466d0cf2782 (diff)
Fixed #2503 -- Fixed HttpResponse.delete_cookie() to work properly. It 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
-rw-r--r--django/http/__init__.py15
-rw-r--r--docs/request_response.txt8
2 files changed, 15 insertions, 8 deletions
diff --git a/django/http/__init__.py b/django/http/__init__.py
index 06f6a106ee..c4ac302ec5 100644
--- a/django/http/__init__.py
+++ b/django/http/__init__.py
@@ -38,7 +38,7 @@ class HttpRequest(object):
def get_full_path(self):
return ''
-
+
def is_secure(self):
return os.environ.get("HTTPS") == "on"
@@ -203,11 +203,14 @@ class HttpResponse(object):
if val is not None:
self.cookies[key][var.replace('_', '-')] = val
- def delete_cookie(self, key):
- try:
- self.cookies[key]['max_age'] = 0
- except KeyError:
- pass
+ def delete_cookie(self, key, path='/', domain=None):
+ self.cookies[key] = ''
+ if path is not None:
+ self.cookies[key]['path'] = path
+ if domain is not None:
+ self.cookies[key]['domain'] = path
+ self.cookies[key]['expires'] = 0
+ self.cookies[key]['max-age'] = 0
def _get_content(self):
content = ''.join(self._iterator)
diff --git a/docs/request_response.txt b/docs/request_response.txt
index 7480a6d3bb..1f3b9d5804 100644
--- a/docs/request_response.txt
+++ b/docs/request_response.txt
@@ -149,7 +149,7 @@ Methods
Returns the ``path``, plus an appended query string, if applicable.
Example: ``"/music/bands/the_beatles/?print=true"``
-
+
``is_secure()``
Returns ``True`` if the request is secure; that is, if it was made with
HTTPS.
@@ -380,10 +380,14 @@ Methods
.. _`cookie Morsel`: http://www.python.org/doc/current/lib/morsel-objects.html
-``delete_cookie(key)``
+``delete_cookie(key, path='/', domain=None)``
Deletes the cookie with the given key. Fails silently if the key doesn't
exist.
+ The ``path`` and ``domain`` arguments are new in the Django development version.
+ Due to the way cookies work, ``path`` and ``domain`` should be the same
+ values you used in ``set_cookie()`` -- otherwise the cookie may not be deleted.
+
``content``
Returns the content as a Python string, encoding it from a Unicode object
if necessary. Note this is a property, not a method, so use ``r.content``