我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用django.conf.settings.SECURE_PROXY_SSL_HEADER。
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) if django.VERSION >= (1, 9): self.assertRedirects(resp, settings.TESTSERVER + redirect_url) else: 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
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()
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()
def test_x_forwarded_proto_does_nothing_if_wrong_protocol(self): self.assertEqual( settings.SECURE_PROXY_SSL_HEADER, ('HTTP_X_FORWARDED_PROTO', 'https')) request = self.create_request(HTTP_X_FORWARDED_PROTO="ftp") self.assertFalse(request.is_secure()) request = self.create_request(HTTP_X_FORWARDED_PROTO="http") self.assertFalse(request.is_secure())