Created
April 30, 2012 18:22
-
-
Save mtigas/2560758 to your computer and use it in GitHub Desktop.
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
class TrackingCheck(object): | |
""" | |
Allows implementing the HTTP header-based "Do Not Track" mechanism described in | |
http://tools.ietf.org/html/draft-mayer-do-not-track-00 | |
""" | |
def process_request(self, request): | |
# DNT: 1 | |
optout = request.META.get("HTTP_DNT", False) or request.META.get("HTTP_X_DNT", "0") | |
if optout.strip() == "1": | |
setattr(request, "tracking_opt_out", True) | |
return None | |
# X-Do-Not-Track: 1 | |
optout = request.META.get("HTTP_X_DO_NOT_TRACK", "0") | |
if optout.strip() == "1": | |
setattr(request, "tracking_opt_out", True) | |
return None | |
# X-Tracking-Choice: do-not-track | |
optout = request.META.get("HTTP_X_TRACKING_CHOICE", False) or request.META.get("HTTP_TRACKING_PREFERENCE", "") | |
if optout.strip() == "do-not-track": | |
setattr(request, "tracking_opt_out", True) | |
return None | |
def process_response(self, request, response): | |
# We're actually not doing anything with `request.tracking_opt_out` right now. | |
response['DNT'] = "0 (sorry)" | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment