Created
March 8, 2011 16:51
-
-
Save ojii/860529 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
import re | |
from django.conf import settings | |
from django.http import HttpResponseRedirect | |
DEFAULT = 'http://www.getfirefox.com' | |
class IE6CountdownMiddleware(object): | |
""" | |
Do *very* simple user agent scanning and redirect anyone accessing your site | |
using an old Internet Explorer to a website to get a real browser. | |
""" | |
def __init__(self): | |
self.redirect_to = getattr(settings, 'IE6_COUNTDOWN_REDIRECT', DEFAULT) | |
self.min_version = getattr(settings, 'IE6_COUNTDOWN_MIN_VERSION', 6) | |
self.regex = re.compile('MSIE (\d)') | |
def process_request(self, request): | |
user_agent = request.META.get('HTTP_USER_AGENT', '') | |
match = self.regex.search(user_agent) | |
if match and int(match.group(1)) <= self.min_version: | |
return HttpResponseRedirect(self.redirect_to) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment