本文整理汇总了Python中bottle.HTTPResponse.headers['Access-Control-Allow-Origin']方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPResponse.headers['Access-Control-Allow-Origin']方法的具体用法?Python HTTPResponse.headers['Access-Control-Allow-Origin']怎么用?Python HTTPResponse.headers['Access-Control-Allow-Origin']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bottle.HTTPResponse
的用法示例。
在下文中一共展示了HTTPResponse.headers['Access-Control-Allow-Origin']方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: method_not_allowed
# 需要导入模块: from bottle import HTTPResponse [as 别名]
# 或者: from bottle.HTTPResponse import headers['Access-Control-Allow-Origin'] [as 别名]
def method_not_allowed(res):
if request.method == 'OPTIONS':
new_res = HTTPResponse()
new_res.headers['Access-Control-Allow-Origin'] = '*'
new_res.headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS, PUT'
new_res.headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept'
return new_res
res.headers['Allow'] += ', OPTIONS'
return request.app.default_error_handler(res)
示例2: make_error
# 需要导入模块: from bottle import HTTPResponse [as 别名]
# 或者: from bottle.HTTPResponse import headers['Access-Control-Allow-Origin'] [as 别名]
def make_error(message):
formats = {
'json': 'application/json',
'xml': 'application/xml',
'jsonp': 'application/javascript',
}
format_ = bottle.request.query.get('format', 'json')
response = HTTPResponse(status=message, content_type=formats[format_])
response.headers['Access-Control-Allow-Origin'] = '*'
return response
示例3: _handle
# 需要导入模块: from bottle import HTTPResponse [as 别名]
# 或者: from bottle.HTTPResponse import headers['Access-Control-Allow-Origin'] [as 别名]
def _handle(self, callback, conf, func_args, *args, **kwargs):
meth = request.method.lower()
path = request.path
filters = self._kwargs['filters']
is_pass = True
for pattern, methes in filters:
if pattern.match(path) and ((meth in methes) or ('all' in methes)):
is_pass = False
break
rv = callback(*args, **kwargs)
if is_pass:
if not isinstance(rv, HTTPResponse):
rv = HTTPResponse(rv)
rv.headers['Access-Control-Allow-Origin'] = '*'
rv.headers['Access-Control-Allow-Methods'] = \
'GET,POST,PUT,OPTIONS'
rv.headers['Access-Control-Allow-Headers'] = \
'Referer, Accept, Origin, User-Agent'
return rv