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


Python Request.headers方法代码示例

本文整理汇总了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")
开发者ID:DewArmy,项目名称:privacyidea,代码行数:47,代码来源:test_api_lib_policy.py

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


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