當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。