Created
July 5, 2012 11:56
-
-
Save un33k/3053283 to your computer and use it in GitHub Desktop.
This middleware removes extra back2back slashes from incoming request
This file contains hidden or 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
from django.http import HttpResponseRedirect | |
import re | |
slash_re = re.compile('/{2,}') | |
class SingleSlashes: | |
""" This middleware removes extra back2back slashes from an incoming request """ | |
def process_request(self, request): | |
if '//' in request.path: | |
new_path = slash_re.sub('/', request.path) | |
return HttpResponseRedirect(new_path) | |
else: | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment