allow the configuration to exclude certain HTTP headers

This commit is contained in:
Gonçalo Valério 2019-01-27 16:17:47 +00:00
parent 789ef35bb7
commit e0c9b668b2
3 changed files with 14 additions and 5 deletions

View File

@ -1,2 +1,5 @@
SECRET_KEY= SECRET_KEY=
REDIS_URL= REDIS_URL=
DOMAIN=
ENVIRONMENT=
EXCLUDE_HEADERS=

View File

@ -4,6 +4,7 @@ from django.views.generic import RedirectView, TemplateView, View
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.http import HttpResponse from django.http import HttpResponse
from django.utils import timezone from django.utils import timezone
from django.conf import settings
from channels.layers import get_channel_layer from channels.layers import get_channel_layer
from asgiref.sync import async_to_sync from asgiref.sync import async_to_sync
@ -58,7 +59,7 @@ class CallbackView(View):
request = self.request request = self.request
headers = [] headers = []
for key, value in request.META.items(): for key, value in request.META.items():
if key.startswith("HTTP"): if key.startswith("HTTP") and key not in settings.EXCLUDED_HEADERS:
original_header = ( original_header = (
key.replace("HTTP_", "").replace("_", "-").capitalize() key.replace("HTTP_", "").replace("_", "-").capitalize()
) )

View File

@ -21,12 +21,14 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get("SECRET_KEY") SECRET_KEY = os.environ.get("SECRET_KEY")
APP_ENV = os.environ.get("ENVIRONMENT", "development")
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True if APP_ENV == "development":
DEBUG = True
ALLOWED_HOSTS = [] else:
DEBUG = False
ALLOWED_HOSTS = [os.environ.get("DOMAIN")]
# Application definition # Application definition
@ -102,3 +104,6 @@ CHANNEL_LAYERS = {
"CONFIG": {"hosts": [(os.environ.get("REDIS_URL", "127.0.0.1"), 6379)]}, "CONFIG": {"hosts": [(os.environ.get("REDIS_URL", "127.0.0.1"), 6379)]},
} }
} }
# Should use the format of request.META
EXCLUDED_HEADERS = os.environ.get("EXCLUDE_HEADERS", "").split(",")