Python django.conf.settings.SECURE_PROXY_SSL_HEADER Examples
The following are 11
code examples of django.conf.settings.SECURE_PROXY_SSL_HEADER().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.conf.settings
, or try the search function
.
Example #1
Source File: base.py From avos with Apache License 2.0 | 6 votes |
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
Example #2
Source File: request.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
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()
Example #3
Source File: request.py From bioforum with MIT License | 5 votes |
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()
Example #4
Source File: request.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
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()
Example #5
Source File: request.py From python with Apache License 2.0 | 5 votes |
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()
Example #6
Source File: request.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
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()
Example #7
Source File: request.py From openhgsenti with Apache License 2.0 | 5 votes |
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()
Example #8
Source File: request.py From python2017 with MIT License | 5 votes |
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()
Example #9
Source File: notify_report_due.py From hypha with BSD 3-Clause "New" or "Revised" License | 5 votes |
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}') )
Example #10
Source File: send_reminders.py From hypha with BSD 3-Clause "New" or "Revised" License | 5 votes |
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()
Example #11
Source File: models.py From wagtail with BSD 3-Clause "New" or "Revised" License | 4 votes |
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