本文整理匯總了Python中django.conf.settings.SECURE_PROXY_SSL_HEADER屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.SECURE_PROXY_SSL_HEADER屬性的具體用法?Python settings.SECURE_PROXY_SSL_HEADER怎麽用?Python settings.SECURE_PROXY_SSL_HEADER使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類django.conf.settings
的用法示例。
在下文中一共展示了settings.SECURE_PROXY_SSL_HEADER屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_ssl_redirect_by_proxy
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SECURE_PROXY_SSL_HEADER [as 別名]
def test_ssl_redirect_by_proxy(self):
dogs = horizon.get_dashboard("dogs")
puppies = dogs.get_panel("puppies")
url = puppies.get_absolute_url()
redirect_url = "?".join([settings.LOGIN_URL,
"next=%s" % url])
self.client.logout()
resp = self.client.get(url)
self.assertRedirects(resp, redirect_url)
# Set SSL settings for test server
settings.SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTOCOL',
'https')
resp = self.client.get(url, HTTP_X_FORWARDED_PROTOCOL="https")
self.assertEqual(302, resp.status_code)
self.assertEqual('https://testserver:80%s' % redirect_url,
resp['location'])
# Restore settings
settings.SECURE_PROXY_SSL_HEADER = None
示例2: scheme
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SECURE_PROXY_SSL_HEADER [as 別名]
def scheme(self):
# First, check the SECURE_PROXY_SSL_HEADER setting.
if settings.SECURE_PROXY_SSL_HEADER:
try:
header, value = settings.SECURE_PROXY_SSL_HEADER
except ValueError:
raise ImproperlyConfigured(
'The SECURE_PROXY_SSL_HEADER setting must be a tuple containing two values.'
)
if self.META.get(header, None) == value:
return 'https'
# Failing that, fall back to _get_scheme(), which is a hook for
# subclasses to implement.
return self._get_scheme()
示例3: scheme
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SECURE_PROXY_SSL_HEADER [as 別名]
def scheme(self):
if settings.SECURE_PROXY_SSL_HEADER:
try:
header, value = settings.SECURE_PROXY_SSL_HEADER
except ValueError:
raise ImproperlyConfigured(
'The SECURE_PROXY_SSL_HEADER setting must be a tuple containing two values.'
)
if self.META.get(header) == value:
return 'https'
return self._get_scheme()
示例4: is_secure
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SECURE_PROXY_SSL_HEADER [as 別名]
def is_secure(self):
# First, check the SECURE_PROXY_SSL_HEADER setting.
if settings.SECURE_PROXY_SSL_HEADER:
try:
header, value = settings.SECURE_PROXY_SSL_HEADER
except ValueError:
raise ImproperlyConfigured('The SECURE_PROXY_SSL_HEADER setting must be a tuple containing two values.')
if self.META.get(header, None) == value:
return True
# Failing that, fall back to _is_secure(), which is a hook for
# subclasses to implement.
return self._is_secure()
示例5: handle
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SECURE_PROXY_SSL_HEADER [as 別名]
def handle(self, *args, **options):
site = ApplyHomePage.objects.first().get_site()
set_urlconf('hypha.apply.urls')
# Mock a HTTPRequest in order to pass the site settings into the
# templates
request = HttpRequest()
request.META['SERVER_NAME'] = site.hostname
request.META['SERVER_PORT'] = site.port
request.META[settings.SECURE_PROXY_SSL_HEADER] = 'https'
request.session = {}
request._messages = FallbackStorage(request)
today = timezone.now().date()
due_date = today + relativedelta(days=options['days_before'])
for project in Project.objects.in_progress():
next_report = project.report_config.current_due_report()
due_soon = next_report.end_date == due_date
not_notified_today = (
not next_report.notified or
next_report.notified.date() != today
)
if due_soon and not_notified_today:
messenger(
MESSAGES.REPORT_NOTIFY,
request=request,
user=None,
source=project,
related=next_report,
)
# Notify about the due report
next_report.notified = timezone.now()
next_report.save()
self.stdout.write(
self.style.SUCCESS(f'Notified project: {project.id}')
)
示例6: handle
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SECURE_PROXY_SSL_HEADER [as 別名]
def handle(self, *args, **options):
site = ApplyHomePage.objects.first().get_site()
set_urlconf('hypha.apply.urls')
# Mock a HTTPRequest in order to pass the site settings into the
# templates
request = HttpRequest()
request.META['SERVER_NAME'] = site.hostname
request.META['SERVER_PORT'] = site.port
request.META[settings.SECURE_PROXY_SSL_HEADER] = 'https'
request.session = {}
request._messages = FallbackStorage(request)
for reminder in Reminder.objects.filter(sent=False, time__lte=timezone.now()):
messenger(
reminder.action_message,
request=request,
user=None,
source=reminder.submission,
related=reminder,
)
self.stdout.write(
self.style.SUCCESS(f'Reminder sent: {reminder.id}')
)
reminder.sent = True
reminder.save()
示例7: _get_dummy_headers
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SECURE_PROXY_SSL_HEADER [as 別名]
def _get_dummy_headers(self, original_request=None):
"""
Return a dict of META information to be included in a faked HttpRequest object to pass to
serve_preview.
"""
url = self._get_dummy_header_url(original_request)
if url:
url_info = urlparse(url)
hostname = url_info.hostname
path = url_info.path
port = url_info.port or (443 if url_info.scheme == 'https' else 80)
scheme = url_info.scheme
else:
# Cannot determine a URL to this page - cobble one together based on
# whatever we find in ALLOWED_HOSTS
try:
hostname = settings.ALLOWED_HOSTS[0]
if hostname == '*':
# '*' is a valid value to find in ALLOWED_HOSTS[0], but it's not a valid domain name.
# So we pretend it isn't there.
raise IndexError
except IndexError:
hostname = 'localhost'
path = '/'
port = 80
scheme = 'http'
http_host = hostname
if port != (443 if scheme == 'https' else 80):
http_host = '%s:%s' % (http_host, port)
dummy_values = {
'REQUEST_METHOD': 'GET',
'PATH_INFO': path,
'SERVER_NAME': hostname,
'SERVER_PORT': port,
'SERVER_PROTOCOL': 'HTTP/1.1',
'HTTP_HOST': http_host,
'wsgi.version': (1, 0),
'wsgi.input': StringIO(),
'wsgi.errors': StringIO(),
'wsgi.url_scheme': scheme,
'wsgi.multithread': True,
'wsgi.multiprocess': True,
'wsgi.run_once': False,
}
# Add important values from the original request object, if it was provided.
HEADERS_FROM_ORIGINAL_REQUEST = [
'REMOTE_ADDR', 'HTTP_X_FORWARDED_FOR', 'HTTP_COOKIE', 'HTTP_USER_AGENT', 'HTTP_AUTHORIZATION',
'wsgi.version', 'wsgi.multithread', 'wsgi.multiprocess', 'wsgi.run_once',
]
if settings.SECURE_PROXY_SSL_HEADER:
HEADERS_FROM_ORIGINAL_REQUEST.append(settings.SECURE_PROXY_SSL_HEADER[0])
if original_request:
for header in HEADERS_FROM_ORIGINAL_REQUEST:
if header in original_request.META:
dummy_values[header] = original_request.META[header]
return dummy_values