-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from eillarra/patch-1
Add a "Vary" header for DNT, useful for caching.
- Loading branch information
Showing
1 changed file
with
15 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
from django.utils.cache import patch_vary_headers | ||
|
||
|
||
class DoNotTrackMiddleware(object): | ||
"""Sets request.dnt to True or False based on the presence of the | ||
DNT HTTP header.""" | ||
|
||
def process_request(self, request): | ||
""" | ||
Sets request.DNT to True or False based on the presence of the DNT HTTP header. | ||
""" | ||
if 'HTTP_DNT' in request.META and request.META['HTTP_DNT'] == '1': | ||
request.DNT = True | ||
else: | ||
request.DNT = False | ||
|
||
def process_response(self, request, response): | ||
""" | ||
Adds a "Vary" header for DNT, useful for caching. | ||
""" | ||
patch_vary_headers(response, ['DNT']) | ||
|
||
return response |