Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

We only need one middleware because of ordering

  • Loading branch information...
commit 5348a2ceec8f4e395121b69f2079976bade5de31 1 parent 1990615
David Cramer authored
Showing with 5 additions and 12 deletions.
  1. +1 −2  README.rst
  2. +4 −10 djcookies/middleware.py
3  README.rst
View
@@ -10,9 +10,8 @@ Just modify your ``MIDDLEWARE_CLASSES`` setting, order is important here!
:
MIDDLEWARE_CLASSES = (
- 'djcookies.CookiePreHandlerMiddleware',
+ 'djcookies.CookieMiddleware',
...
- 'djcookies.CookiePostHandlerMiddleware',
)
Usage
14 djcookies/middleware.py
View
@@ -5,9 +5,8 @@
`delete` matches django.http.HttpResponse.delete_cookie
MIDDLEWARE_CLASSES = (
- 'djcookies.CookiePreHandlerMiddleware',
+ 'djcookies.CookieMiddleware',
...
- 'djcookies.CookiePostHandlerMiddleware',
)
def my_view(request):
@@ -19,9 +18,10 @@ def my_view(request):
from Cookie import SimpleCookie, Morsel
import copy
-class CookiePreHandlerMiddleware(object):
+class CookieMiddleware(object):
"""
This middleware modifies request.COOKIES and adds a set and delete method.
+ It also updates the response with all modified cookies when finished
`set` matches django.http.HttpResponse.set_cookie
`delete` matches django.http.HttpResponse.delete_cookie
@@ -34,13 +34,7 @@ def process_request(self, request):
cookies[k] = str(v)
request.COOKIES = cookies
request._orig_cookies = copy.deepcopy(request.COOKIES)
-
-class CookiePostHandlerMiddleware(object):
- """
- This middleware modifies updates the response will all modified cookies.
-
- This should be the last middleware you load.
- """
+
def process_response(self, request, response):
if hasattr(request, '_orig_cookies') and request.COOKIES != request._orig_cookies:
for k,v in request.COOKIES.iteritems():
Please sign in to comment.
Something went wrong with that request. Please try again.