Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
mpicms/patches/django-Do-not-check-ALLOWED_HOSTS-for-dummy-requests.patch
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
31 lines (26 sloc)
1.2 KB
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
From 41d351e97c1cc8d8c0bab812eacffb2dcd6e9ad2 Mon Sep 17 00:00:00 2001 | |
From: Donald Buczek <buczek@molgen.mpg.de> | |
Date: Thu, 2 Jan 2020 14:53:04 +0100 | |
Subject: [PATCH] django: Do not check ALLOWED_HOSTS for dummy requests. | |
Bypass check against ALLOWED_HOSTS for requests with the attribute | |
is_dummy set to a true value. | |
This can be used applications which create request themselfs to be | |
handled by django. It is used by wagtail to implement preview. | |
--- | |
lib/python3.7/site-packages/django/http/request.py | 3 +++ | |
1 file changed, 3 insertions(+) | |
diff --git a/lib/python3.7/site-packages/django/http/request.py b/lib/python3.7/site-packages/django/http/request.py | |
index 083bf2d..4b8c9a9 100644 | |
--- a/lib/python3.7/site-packages/django/http/request.py | |
+++ b/lib/python3.7/site-packages/django/http/request.py | |
@@ -120,6 +120,9 @@ class HttpRequest: | |
"""Return the HTTP host using the environment or request headers.""" | |
host = self._get_raw_host() | |
+ if getattr(self, 'is_dummy', False): | |
+ return host | |
+ | |
# Allow variants of localhost if ALLOWED_HOSTS is empty and DEBUG=True. | |
allowed_hosts = settings.ALLOWED_HOSTS | |
if settings.DEBUG and not allowed_hosts: | |
-- | |
2.26.2 | |