Skip to content

Instantly share code, notes, and snippets.

@rrafal
Last active February 5, 2020 08:19
Show Gist options
  • Save rrafal/e176f7f0de255fc16fa4 to your computer and use it in GitHub Desktop.
Save rrafal/e176f7f0de255fc16fa4 to your computer and use it in GitHub Desktop.
Django logging filter for Invalid HTTP_HOST header
class IgnoreHostError(logging.Filter):
def filter(self, record):
from django.core.exceptions import SuspiciousOperation
if record.name == 'django.security.DisallowedHost':
return False
if record.name == 'django.core.exceptions.DisallowedHost':
return False
if record.exc_info:
exc_value = record.exc_info[1]
if isinstance(exc_value, SuspiciousOperation):
return False
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment