本文整理汇总了Python中bottle.response.headers方法的典型用法代码示例。如果您正苦于以下问题:Python response.headers方法的具体用法?Python response.headers怎么用?Python response.headers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bottle.response
的用法示例。
在下文中一共展示了response.headers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_route
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import headers [as 别名]
def parse_route(content, user_id):
if re.search('!@\[[_a-zA-Z0-9:]*\]', content):
response.headers["B9Y-ROUTES"] = "parsed"
repl1 = re.sub('!@\[[_a-zA-Z0-9:]*\]', '_B9yPrsE_\\g<0>_B9yPrsE_', content)
items = repl1.split("_B9yPrsE_")
out = ""
for i in items:
if i.startswith("!@["):
key = re.sub('[^\w:]', "", i)
val = rc.get("KEY:"+str(user_id)+"::"+str(key))
if val != None:
out += val
else:
out += str(i)
return(out)
else:
return(content)
# Key names must match this regex
示例2: __call__
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import headers [as 别名]
def __call__(self, callback):
def wrapper(*args, **kwargs):
if not is_local_request():
self._logger.info('Dropping request with bad Host header.')
abort(httplib.UNAUTHORIZED,
'Unauthorized, received request from non-local Host.')
return
if not self.is_request_authenticated():
self._logger.info('Dropping request with bad HMAC.')
abort(httplib.UNAUTHORIZED, 'Unauthorized, received bad HMAC.')
return
body = callback(*args, **kwargs)
self.sign_response_headers(response.headers, body)
return body
return wrapper
示例3: create_app
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import headers [as 别名]
def create_app():
app = bottle.app()
_route(app, '/emails', ['GET'], resource.get_emails)
_route(
app, '/emails/<email_id:int>', ['DELETE'],
resource.delete_email)
_route(
app, '/raw_messages/<raw_message_id>', ['GET'],
resource.get_raw_message)
@app.hook('after_request')
def enable_cors():
ALLOWED_METHODS = 'PUT, GET, POST, DELETE, OPTIONS'
ALLOWED_HEADERS = \
'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = ALLOWED_METHODS
response.headers['Access-Control-Allow-Headers'] = ALLOWED_HEADERS
return app
示例4: get_route
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import headers [as 别名]
def get_route(id, dummy=0, dummy2=0):
route_key = "ROUTE:"+str(id)
# Read Route from Redis
try:
route_content = rc.get(route_key)
if route_content == None:
raise ValueError('not found')
route_record = json.loads(route_content)
user_id = route_record["user_id"]
key = route_record["key"]
content_type = route_record["content_type"]
except:
response.status = 404
return dict({"info":"Not found."})
# Construct Resource Location from user_id and id
redis_key = "KEY:"+str(user_id)+"::"+str(key)
# Read from Redis
try:
key_content = rc.get(redis_key)
if key_content == None:
raise ValueError('not found.')
except:
response.status = 404
return dict({"info":"Not found."})
response.headers['Access-Control-Allow-Origin'] = '*'
response.content_type = content_type
return(parse_route(str(key_content), user_id))
# Create Bins
示例5: _authenticate
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import headers [as 别名]
def _authenticate():
# Token can be in query string or AUTH header
if 'token' in request.query:
access_token = request.query["token"]
else:
bearer = request.environ.get('HTTP_AUTHORIZATION','')
access_token=bearer[7:]
# Extract the data from the token
data = _get_token_data(token=access_token)
# If there was an error, end here
if data["error"] != "0":
return(dict(data))
# Was the token issued by this cluster?
if data["cluster_id"] != cluster_id:
return(dict(data))
# Is the access token still valid?
token_timestamp = data["timestamp"]
current_time = int(time.time())
delta = current_time - token_timestamp
if delta > token_expiry_seconds:
# expired
data["authenticated"] = "False"
data["info"] = "Token expired"
else:
# valid
data["authenticated"] = "True"
data["info"] = "Session expires in " + str(token_expiry_seconds - delta) + " seconds."
# Set response header: username
response.headers["B9Y-AUTHENTICATED-USER"] = data["user"]
return(dict(data))
示例6: enable_cors
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import headers [as 别名]
def enable_cors():
"""
Enable CORS support.
:return:
"""
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'PUT, GET, POST, DELETE, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'
示例7: to_json
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import headers [as 别名]
def to_json(fnc):
@wraps(fnc)
def inner(*args, **kwargs):
bottle_resp.headers['Content-Type'] = 'application/json'
from_func = fnc(*args, **kwargs)
if from_func is not None:
return json.dumps({'result': from_func})
return inner
示例8: enable_cors
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import headers [as 别名]
def enable_cors():
response.headers['Access-Control-Allow-Origin'] = '*'
示例9: __init__
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import headers [as 别名]
def __init__(self, output='', status=200, header=None):
super(BottleException, self).__init__("HTTP Response %d" % status)
self.status = int(status)
self.output = output
self.headers = HeaderDict(header) if header else None
示例10: apply
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import headers [as 别名]
def apply(self, response):
if self.headers:
for key, value in self.headers.iterallitems():
response.headers[key] = value
response.status = self.status
示例11: header
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import headers [as 别名]
def header(self):
''' :class:`HeaderDict` filled with request headers.
HeaderDict keys are case insensitive str.title()d
'''
if self._header is None:
self._header = HeaderDict()
for key, value in self.environ.iteritems():
if key.startswith('HTTP_'):
key = key[5:].replace('_','-').title()
self._header[key] = value
return self._header
示例12: bind
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import headers [as 别名]
def bind(self, app):
""" Resets the Response object to its factory defaults. """
self._COOKIES = None
self.status = 200
self.headers = HeaderDict()
self.content_type = 'text/html; charset=UTF-8'
self.app = app
示例13: wsgiheader
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import headers [as 别名]
def wsgiheader(self):
''' Returns a wsgi conform list of header/value pairs. '''
for c in self.COOKIES.values():
if c.OutputString() not in self.headers.getall('Set-Cookie'):
self.headers.append('Set-Cookie', c.OutputString())
return list(self.headers.iterallitems())
示例14: get_content_type
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import headers [as 别名]
def get_content_type(self):
""" Current 'Content-Type' header. """
return self.headers['Content-Type']
示例15: set_content_type
# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import headers [as 别名]
def set_content_type(self, value):
self.headers['Content-Type'] = value