当前位置: 首页>>代码示例>>Python>>正文


Python response.headers方法代码示例

本文整理汇总了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 
开发者ID:u1i,项目名称:bambleweeny,代码行数:21,代码来源:bambleweeny.py

示例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 
开发者ID:vheon,项目名称:JediHTTP,代码行数:19,代码来源:hmac_plugin.py

示例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 
开发者ID:kevinjqiu,项目名称:mailchute,代码行数:22,代码来源:app.py

示例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 
开发者ID:u1i,项目名称:bambleweeny,代码行数:37,代码来源:bambleweeny.py

示例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)) 
开发者ID:u1i,项目名称:bambleweeny,代码行数:37,代码来源:bambleweeny.py

示例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' 
开发者ID:Jorl17,项目名称:open-elevation,代码行数:10,代码来源:server.py

示例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 
开发者ID:felipevolpone,项目名称:ray,代码行数:10,代码来源:api.py

示例8: enable_cors

# 需要导入模块: from bottle import response [as 别名]
# 或者: from bottle.response import headers [as 别名]
def enable_cors():
    response.headers['Access-Control-Allow-Origin'] = '*' 
开发者ID:shariq,项目名称:burgundy,代码行数:4,代码来源:wordserver.py

示例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 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:7,代码来源:bottle2.py

示例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 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:7,代码来源:bottle2.py

示例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 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:14,代码来源:bottle2.py

示例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 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:9,代码来源:bottle2.py

示例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()) 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:8,代码来源:bottle2.py

示例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'] 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:5,代码来源:bottle2.py

示例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 
开发者ID:lrq3000,项目名称:pyFileFixity,代码行数:4,代码来源:bottle2.py


注:本文中的bottle.response.headers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。