* Kommentare wenn Dan/Kyu Punktabzüge verringert werden um nicht unter
0 zu fallen. * Neue Middleware die REMOTE_IP aus dem X-Forward-For Header setzt. Damit funktioniert das Kommentarsystem nun auch hinter nginx.
This commit is contained in:
@@ -4,14 +4,14 @@ from django.utils.html import strip_spaces_between_tags
|
||||
|
||||
|
||||
class CompressHtmlMiddleware(object):
|
||||
"""This Middleware compresses strips the spaces between tags, and at the
|
||||
"""This Middleware compresses strips the spaces between tags, and at the
|
||||
beginning and the end of the content."""
|
||||
# TODO: Port to django 1.10 and upward
|
||||
|
||||
def __init__(self, get_response):
|
||||
"""
|
||||
|
||||
:param get_response:
|
||||
:param get_response:
|
||||
"""
|
||||
self.get_response = get_response
|
||||
regex = ">[\s]*<"
|
||||
@@ -19,8 +19,8 @@ class CompressHtmlMiddleware(object):
|
||||
def __call__(self, request):
|
||||
"""
|
||||
|
||||
:param request:
|
||||
:return:
|
||||
:param request:
|
||||
:return:
|
||||
"""
|
||||
|
||||
# Code to be executed for each request before
|
||||
@@ -31,3 +31,15 @@ class CompressHtmlMiddleware(object):
|
||||
response.content = strip_spaces_between_tags(
|
||||
response.content).strip()
|
||||
return response
|
||||
|
||||
class SetRemoteAddrFromForwardedFor(object):
|
||||
def process_request(self, request):
|
||||
try:
|
||||
real_ip = request.META['HTTP_X_FORWARDED_FOR']
|
||||
real_ip = real_ip.split(",")[0]
|
||||
except KeyError:
|
||||
pass
|
||||
else:
|
||||
# HTTP_X_FORWARDED_FOR can be a comma-separated list of IPs.
|
||||
# Take just the first one.
|
||||
request.META['REMOTE_ADDR'] = real_ip
|
||||
|
||||
Reference in New Issue
Block a user