本文整理汇总了Python中flask.Request.headers方法的典型用法代码示例。如果您正苦于以下问题:Python Request.headers方法的具体用法?Python Request.headers怎么用?Python Request.headers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.Request
的用法示例。
在下文中一共展示了Request.headers方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_11_api_key_required
# 需要导入模块: from flask import Request [as 别名]
# 或者: from flask.Request import headers [as 别名]
def test_11_api_key_required(self):
g.logged_in_user = {}
builder = EnvironBuilder(method='POST',
data={'serial': "OATH123456"},
headers={})
env = builder.get_environ()
# Set the remote address so that we can filter for it
env["REMOTE_ADDR"] = "10.0.0.1"
g.client_ip = env["REMOTE_ADDR"]
req = Request(env)
g.policy_object = PolicyClass()
# No policy and no Auth token
req.all_data = {}
r = api_key_required(req)
# The request was not modified
self.assertTrue(r)
# Set a policy, that allows two tokens per realm
set_policy(name="pol_api",
scope=SCOPE.AUTHZ,
action=ACTION.APIKEY)
g.policy_object = PolicyClass()
# A request with no API Key fails
self.assertRaises(PolicyError, api_key_required, req)
# A request with an API key succeeds
secret = current_app.config.get("SECRET_KEY")
token = jwt.encode({"role": ROLE.VALIDATE,
"exp": datetime.utcnow() + timedelta(hours=1)},
secret)
req.headers = {"Authorization": token}
r = api_key_required(req)
self.assertTrue(r)
# A request with a valid Admin Token does not succeed
token = jwt.encode({"role": ROLE.ADMIN,
"username": "admin",
"exp": datetime.utcnow() + timedelta(hours=1)},
secret)
req.headers = {"Authorization": token}
self.assertRaises(PolicyError, api_key_required, req)
delete_policy("pol_api")
示例2: test_authenticated
# 需要导入模块: from flask import Request [as 别名]
# 或者: from flask.Request import headers [as 别名]
def test_authenticated(self):
secret = 'Basic {0}'.format(self.get_hash())
h = {'Authorization': secret}
r = Request({})
r.headers = MultiDict(h)
self.assertTrue(charon.views.authenticated(r))