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


Python Response.headers["Access-Control-Allow-Methods"]方法代码示例

本文整理汇总了Python中webob.response.Response.headers["Access-Control-Allow-Methods"]方法的典型用法代码示例。如果您正苦于以下问题:Python Response.headers["Access-Control-Allow-Methods"]方法的具体用法?Python Response.headers["Access-Control-Allow-Methods"]怎么用?Python Response.headers["Access-Control-Allow-Methods"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在webob.response.Response的用法示例。


在下文中一共展示了Response.headers["Access-Control-Allow-Methods"]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: cors_enabled_fn

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import headers["Access-Control-Allow-Methods"] [as 别名]
     def cors_enabled_fn(self, request, *args, **kwargs): # pylint: disable=W0613
         '''This method provides the algorithm for building a generic cors response for the current request.'''
         
         kwargs = kwargs or {}
 
         response = Response(content_type="application/json", status_code=200)
         response.headers["Content-Length"] = "0"
         response.headers["Cache-Control"] = "private"
         response.headers["Access-Control-Allow-Origin"] = "*"
         response.headers["Access-Control-Allow-Methods"] = "OPTIONS,GET,POST,PUT,DELETE"
         response.headers["Access-Control-Allow-Headers"] = request.headers.get("Access-Control-Request-Headers", "")
 
         return response
开发者ID:rcosnita,项目名称:fantastico,代码行数:15,代码来源:controller_decorators.py

示例2: list_registered_resources

# 需要导入模块: from webob.response import Response [as 别名]
# 或者: from webob.response.Response import headers["Access-Control-Allow-Methods"] [as 别名]
    def list_registered_resources(self, request):
        """This method list all registered resources as well as a link to their entry point.

        .. code-block:: javascript

            // ROA api is mapped on a subdomain: roa.fantasticoproject.com
            // listing is done by GET http://fantasticoproject.com/roa/resources HTTP/1.1

            {
                "Person": {1.0 : "http://roa.fantasticoproject.com/1.0/persons",
                           "latest": "http://roa.fantasticoproject.com/latest/persons"},
                "Address": {1.0 : "http://roa.fantasticoproject.com/1.0/addresses",
                            2.0 : "http://roa.fantasticoproject.com/2.0/addresses",
                            "latest": "http://roa.fantasticoproject.com/latest/addresses"}
            }

        .. code-block:: javascript

            // ROA api is mapped on a relative path of the project: http://fantasticoproject.com/api/
            // listing is done by GET http://fantasticoproject.com/roa/resources HTTP/1.1

            {
                "Person": {1.0 : "http://fantasticoproject.com/api/1.0/persons",
                           "latest": "http://roa.fantasticoproject.com/api/latest/persons"},
                "Address": {1.0 : "http://roa.fantasticoproject.com/api/1.0/addresses",
                            2.0 : "http://roa.fantasticoproject.com/api/2.0/addresses",
                            "latest": "http://roa.fantasticoproject.com/api/latest/addresses"}
            }"""

        body = {}
        resources = self._registry.all_resources()

        for resource in resources:
            if not body.get(resource.name):
                body[resource.name] = {}

            api_url = roa_helper.calculate_resource_url(self._roa_api, resource, resource.version)
            api_url_latest = roa_helper.calculate_resource_url(self._roa_api, resource, "latest")

            body[resource.name][resource.version] = api_url
            body[resource.name]["latest"] = api_url_latest

        body = json.dumps(body).encode()

        response = Response(body=body, content_type="application/json", charset="UTF-8")
        response.headers["Access-Control-Allow-Origin"] = "*"
        response.headers["Access-Control-Allow-Methods"] = "OPTIONS,GET,POST,PUT,DELETE"

        return response
开发者ID:rcosnita,项目名称:fantastico,代码行数:51,代码来源:discovery_controller.py


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