本文整理汇总了Python中oslo_middleware.cors.CORS属性的典型用法代码示例。如果您正苦于以下问题:Python cors.CORS属性的具体用法?Python cors.CORS怎么用?Python cors.CORS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类oslo_middleware.cors
的用法示例。
在下文中一共展示了cors.CORS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_app
# 需要导入模块: from oslo_middleware import cors [as 别名]
# 或者: from oslo_middleware.cors import CORS [as 别名]
def load_app(conf, not_implemented_middleware=True):
global APPCONFIGS
# Build the WSGI app
cfg_path = conf.api.paste_config
if not os.path.isabs(cfg_path):
cfg_path = conf.find_file(cfg_path)
if cfg_path is None or not os.path.exists(cfg_path):
LOG.debug("No api-paste configuration file found! Using default.")
cfg_path = os.path.abspath(pkg_resources.resource_filename(
__name__, "api-paste.ini"))
config = dict(conf=conf,
not_implemented_middleware=not_implemented_middleware)
configkey = str(uuid.uuid4())
APPCONFIGS[configkey] = config
LOG.info("WSGI config used: %s", cfg_path)
appname = "gnocchi+" + conf.api.auth_mode
app = deploy.loadapp("config:" + cfg_path, name=appname,
global_conf={'configkey': configkey})
return http_proxy_to_wsgi.HTTPProxyToWSGI(
cors.CORS(app, conf=conf), conf=conf)
示例2: test_application
# 需要导入模块: from oslo_middleware import cors [as 别名]
# 或者: from oslo_middleware.cors import CORS [as 别名]
def test_application(req):
if req.path_info == '/server_cors':
# Mirror back the origin in the request.
response = webob.Response(status=200)
response.headers['Access-Control-Allow-Origin'] = \
req.headers['Origin']
response.headers['X-Server-Generated-Response'] = '1'
return response
if req.path_info == '/server_cors_vary':
# Mirror back the origin in the request.
response = webob.Response(status=200)
response.headers['Vary'] = 'Custom-Vary'
return response
if req.path_info == '/server_no_cors':
# Send a response with no CORS headers.
response = webob.Response(status=200)
return response
if req.method == 'OPTIONS':
raise exc.HTTPNotFound()
return 'Hello World'
示例3: test_expose_headers
# 需要导入模块: from oslo_middleware import cors [as 别名]
# 或者: from oslo_middleware.cors import CORS [as 别名]
def test_expose_headers(self):
"""CORS Specification Section 6.1.4
If the list of exposed headers is not empty add one or more
Access-Control-Expose-Headers headers, with as values the header field
names given in the list of exposed headers.
"""
for method in self.methods:
request = webob.Request.blank('/')
request.method = method
request.headers['Origin'] = 'http://headers.example.com'
response = request.get_response(self.application)
self.assertCORSResponse(response,
status='200 OK',
allow_origin='http://headers.example.com',
max_age=None,
allow_methods=None,
allow_headers=None,
allow_credentials=None,
expose_headers='X-Header-1,X-Header-2',
has_content_type=True)
示例4: test_application_options_response
# 需要导入模块: from oslo_middleware import cors [as 别名]
# 或者: from oslo_middleware.cors import CORS [as 别名]
def test_application_options_response(self):
"""Assert that an application provided OPTIONS response is honored.
If the underlying application, via middleware or other, provides a
CORS response, its response should be honored.
"""
test_origin = 'http://creds.example.com'
request = webob.Request.blank('/server_cors')
request.method = "GET"
request.headers['Origin'] = test_origin
request.headers['Access-Control-Request-Method'] = 'GET'
response = request.get_response(self.application)
# If the regular CORS handling catches this request, it should set
# the allow credentials header. This makes sure that it doesn't.
self.assertNotIn('Access-Control-Allow-Credentials', response.headers)
self.assertEqual(response.headers['Access-Control-Allow-Origin'],
test_origin)
self.assertEqual(response.headers['X-Server-Generated-Response'],
'1')
示例5: test_no_origin_header
# 需要导入模块: from oslo_middleware import cors [as 别名]
# 或者: from oslo_middleware.cors import CORS [as 别名]
def test_no_origin_header(self):
"""CORS Specification Section 6.2.1
If the Origin header is not present terminate this set of steps. The
request is outside the scope of this specification.
"""
request = webob.Request.blank('/')
request.method = "OPTIONS"
response = request.get_response(self.application)
self.assertCORSResponse(response,
status='200 OK',
allow_origin=None,
max_age=None,
allow_methods=None,
allow_headers=None,
allow_credentials=None,
expose_headers=None)
示例6: test_invalid_method
# 需要导入模块: from oslo_middleware import cors [as 别名]
# 或者: from oslo_middleware.cors import CORS [as 别名]
def test_invalid_method(self):
"""CORS Specification Section 6.2.3
If method is not a case-sensitive match for any of the values in
list of methods do not set any additional headers and terminate this
set of steps.
"""
request = webob.Request.blank('/')
request.method = "OPTIONS"
request.headers['Origin'] = 'http://get.example.com'
request.headers['Access-Control-Request-Method'] = 'get'
response = request.get_response(self.application)
self.assertCORSResponse(response,
status='200 OK',
allow_origin=None,
max_age=None,
allow_methods=None,
allow_headers=None,
allow_credentials=None,
expose_headers=None)
示例7: test_no_parse_request_headers
# 需要导入模块: from oslo_middleware import cors [as 别名]
# 或者: from oslo_middleware.cors import CORS [as 别名]
def test_no_parse_request_headers(self):
"""CORS Specification Section 6.2.4
If there are no Access-Control-Request-Headers headers let header
field-names be the empty list.
If parsing failed do not set any additional headers and terminate
this set of steps. The request is outside the scope of this
specification.
"""
request = webob.Request.blank('/')
request.method = "OPTIONS"
request.headers['Origin'] = 'http://headers.example.com'
request.headers['Access-Control-Request-Method'] = 'GET'
request.headers['Access-Control-Request-Headers'] = 'value with spaces'
response = request.get_response(self.application)
self.assertCORSResponse(response,
status='200 OK',
allow_origin=None,
max_age=None,
allow_methods=None,
allow_headers=None,
allow_credentials=None,
expose_headers=None)
示例8: test_no_request_headers
# 需要导入模块: from oslo_middleware import cors [as 别名]
# 或者: from oslo_middleware.cors import CORS [as 别名]
def test_no_request_headers(self):
"""CORS Specification Section 6.2.4
If there are no Access-Control-Request-Headers headers let header
field-names be the empty list.
"""
request = webob.Request.blank('/')
request.method = "OPTIONS"
request.headers['Origin'] = 'http://headers.example.com'
request.headers['Access-Control-Request-Method'] = 'GET'
request.headers['Access-Control-Request-Headers'] = ''
response = request.get_response(self.application)
self.assertCORSResponse(response,
status='200 OK',
allow_origin='http://headers.example.com',
max_age=None,
allow_methods='GET',
allow_headers=None,
allow_credentials=None,
expose_headers=None)
示例9: test_request_headers_not_permitted
# 需要导入模块: from oslo_middleware import cors [as 别名]
# 或者: from oslo_middleware.cors import CORS [as 别名]
def test_request_headers_not_permitted(self):
"""CORS Specification Section 6.2.4, 6.2.6
If there are no Access-Control-Request-Headers headers let header
field-names be the empty list.
If any of the header field-names is not a ASCII case-insensitive
match for any of the values in list of headers do not set any
additional headers and terminate this set of steps.
"""
request = webob.Request.blank('/')
request.method = "OPTIONS"
request.headers['Origin'] = 'http://headers.example.com'
request.headers['Access-Control-Request-Method'] = 'GET'
request.headers['Access-Control-Request-Headers'] = 'X-Not-Exposed,' \
'X-Never-Exposed'
response = request.get_response(self.application)
self.assertCORSResponse(response,
status='200 OK',
allow_origin=None,
max_age=None,
allow_methods=None,
allow_headers=None,
allow_credentials=None,
expose_headers=None)
示例10: test_optional_max_age
# 需要导入模块: from oslo_middleware import cors [as 别名]
# 或者: from oslo_middleware.cors import CORS [as 别名]
def test_optional_max_age(self):
"""CORS Specification Section 6.2.8
Optionally add a single Access-Control-Max-Age header with as value
the amount of seconds the user agent is allowed to cache the result of
the request.
"""
request = webob.Request.blank('/')
request.method = "OPTIONS"
request.headers['Origin'] = 'http://cached.example.com'
request.headers['Access-Control-Request-Method'] = 'GET'
response = request.get_response(self.application)
self.assertCORSResponse(response,
status='200 OK',
allow_origin='http://cached.example.com',
max_age=3600,
allow_methods='GET',
allow_headers=None,
allow_credentials=None,
expose_headers=None)
示例11: setUp
# 需要导入模块: from oslo_middleware import cors [as 别名]
# 或者: from oslo_middleware.cors import CORS [as 别名]
def setUp(self):
super(CORSTestWildcard, self).setUp()
fixture = self.config_fixture # Line length accommodation
fixture.load_raw_values(group='cors',
allowed_origin='http://default.example.com',
allow_credentials='True',
max_age='',
expose_headers='',
allow_methods='GET,PUT,POST,DELETE,HEAD',
allow_headers='')
fixture.load_raw_values(group='cors.wildcard',
allowed_origin='*',
allow_methods='GET')
# Now that the config is set up, create our application.
self.application = cors.CORS(test_application, self.config)
示例12: _wrap_app
# 需要导入模块: from oslo_middleware import cors [as 别名]
# 或者: from oslo_middleware.cors import CORS [as 别名]
def _wrap_app(app):
"""Wraps wsgi app with additional middlewares."""
app = request_id.RequestId(app)
if CONF.audit.enabled:
try:
app = audit_middleware.AuditMiddleware(
app,
audit_map_file=CONF.audit.audit_map_file,
ignore_req_list=CONF.audit.ignore_req_list
)
except (EnvironmentError, OSError,
audit_middleware.PycadfAuditApiConfigError) as e:
raise exceptions.InputFileError(
file_name=CONF.audit.audit_map_file,
reason=e
)
if cfg.CONF.api_settings.auth_strategy == constants.KEYSTONE:
app = keystone.SkippingAuthProtocol(app, {})
app = http_proxy_to_wsgi.HTTPProxyToWSGI(app)
# This should be the last middleware in the list (which results in
# it being the first in the middleware chain). This is to ensure
# that any errors thrown by other middleware, such as an auth
# middleware - are annotated with CORS headers, and thus accessible
# by the browser.
app = cors.CORS(app, cfg.CONF)
cors.set_defaults(
allow_headers=['X-Auth-Token', 'X-Openstack-Request-Id'],
allow_methods=['GET', 'PUT', 'POST', 'DELETE'],
expose_headers=['X-Auth-Token', 'X-Openstack-Request-Id']
)
return app
示例13: test_cor_config_sections_with_defaults
# 需要导入模块: from oslo_middleware import cors [as 别名]
# 或者: from oslo_middleware.cors import CORS [as 别名]
def test_cor_config_sections_with_defaults(self):
'''Assert cors.* config sections with default values work.'''
# Set up the config fixture.
self.config_fixture.load_raw_values(group='cors.subdomain')
# Now that the config is set up, create our application.
self.application = cors.CORS(test_application, self.config)
示例14: test_simple_header_response
# 需要导入模块: from oslo_middleware import cors [as 别名]
# 或者: from oslo_middleware.cors import CORS [as 别名]
def test_simple_header_response(self):
"""CORS Specification Section 3
A header is said to be a simple header if the header field name is an
ASCII case-insensitive match for Accept, Accept-Language, or
Content-Language or if it is an ASCII case-insensitive match for
Content-Type and the header field value media type (excluding
parameters) is an ASCII case-insensitive match for
application/x-www-form-urlencoded, multipart/form-data, or text/plain.
NOTE: We are not testing the media type cases.
"""
simple_headers = ','.join([
'accept',
'accept-language',
'content-language',
'content-type'
])
request = webob.Request.blank('/')
request.method = "OPTIONS"
request.headers['Origin'] = 'http://valid.example.com'
request.headers['Access-Control-Request-Method'] = 'GET'
request.headers['Access-Control-Request-Headers'] = simple_headers
response = request.get_response(self.application)
self.assertCORSResponse(response,
status='200 OK',
allow_origin='http://valid.example.com',
max_age=None,
allow_methods='GET',
allow_headers=simple_headers,
allow_credentials=None,
expose_headers=None)
示例15: test_credentials
# 需要导入模块: from oslo_middleware import cors [as 别名]
# 或者: from oslo_middleware.cors import CORS [as 别名]
def test_credentials(self):
"""CORS Specification Section 6.2.7
If the resource supports credentials add a single
Access-Control-Allow-Origin header, with the value of the Origin header
as value, and add a single Access-Control-Allow-Credentials header with
the case-sensitive string "true" as value.
Otherwise, add a single Access-Control-Allow-Origin header, with either
the value of the Origin header or the string "*" as value.
NOTE: We never use the "*" as origin.
"""
request = webob.Request.blank('/')
request.method = "OPTIONS"
request.headers['Origin'] = 'http://creds.example.com'
request.headers['Access-Control-Request-Method'] = 'GET'
response = request.get_response(self.application)
self.assertCORSResponse(response,
status='200 OK',
allow_origin='http://creds.example.com',
max_age=None,
allow_methods='GET',
allow_headers=None,
allow_credentials="true",
expose_headers=None)