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


Python hdrs.METH_OPTIONS属性代码示例

本文整理汇总了Python中aiohttp.hdrs.METH_OPTIONS属性的典型用法代码示例。如果您正苦于以下问题:Python hdrs.METH_OPTIONS属性的具体用法?Python hdrs.METH_OPTIONS怎么用?Python hdrs.METH_OPTIONS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在aiohttp.hdrs的用法示例。


在下文中一共展示了hdrs.METH_OPTIONS属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process

# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_OPTIONS [as 别名]
def process(self):
        request = self.request

        if request.method == hdrs.METH_OPTIONS:
            headers = (
                (hdrs.CONTENT_TYPE, "application/javascript; charset=UTF-8"),
                (hdrs.ACCESS_CONTROL_ALLOW_METHODS, "OPTIONS, POST"),
            )
            headers += session_cookie(request)
            headers += cors_headers(request.headers)
            headers += cache_headers()
            return web.Response(status=204, headers=headers)

        headers = (
            (hdrs.CONTENT_TYPE, "application/javascript; charset=UTF-8"),
            (hdrs.CACHE_CONTROL, CACHE_CONTROL),
        )
        headers += session_cookie(request)
        headers += cors_headers(request.headers)

        resp = self.response = web.StreamResponse(headers=headers)
        await resp.prepare(request)

        await self.handle_session()
        return resp 
开发者ID:aio-libs,项目名称:sockjs,代码行数:27,代码来源:xhr.py

示例2: options

# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_OPTIONS [as 别名]
def options(path: str, **kwargs: Any) -> WebHandlerDecorator:
    return handle(hdrs.METH_OPTIONS, path, **kwargs) 
开发者ID:maubot,项目名称:maubot,代码行数:4,代码来源:web.py

示例3: process

# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_OPTIONS [as 别名]
def process(self):
        request = self.request

        if request.method not in (hdrs.METH_GET, hdrs.METH_POST, hdrs.METH_OPTIONS):
            return web.HTTPForbidden(text="Method is not allowed")

        if self.request.method == hdrs.METH_OPTIONS:
            headers = (
                (hdrs.ACCESS_CONTROL_ALLOW_METHODS, "OPTIONS, POST"),
                (hdrs.CONTENT_TYPE, "application/javascript; charset=UTF-8"),
            )
            headers += session_cookie(request)
            headers += cors_headers(request.headers)
            headers += cache_headers()
            return web.Response(status=204, headers=headers)

        data = await request.read()
        if not data:
            return web.HTTPInternalServerError(text="Payload expected.")

        try:
            messages = loads(data.decode(ENCODING))
        except Exception:
            return web.HTTPInternalServerError(text="Broken JSON encoding.")

        await self.session._remote_messages(messages)

        headers = (
            (hdrs.CONTENT_TYPE, "text/plain; charset=UTF-8"),
            (hdrs.CACHE_CONTROL, CACHE_CONTROL),
        )
        headers += session_cookie(request)
        headers += cors_headers(request.headers)

        return web.Response(status=204, headers=headers) 
开发者ID:aio-libs,项目名称:sockjs,代码行数:37,代码来源:xhrsend.py

示例4: process

# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_OPTIONS [as 别名]
def process(self):
        request = self.request
        headers = (
            (hdrs.CONNECTION, request.headers.get(hdrs.CONNECTION, "close")),
            (hdrs.CONTENT_TYPE, "application/javascript; charset=UTF-8"),
            (hdrs.CACHE_CONTROL, CACHE_CONTROL),
        )

        headers += session_cookie(request)
        headers += cors_headers(request.headers)

        if request.method == hdrs.METH_OPTIONS:
            headers += ((hdrs.ACCESS_CONTROL_ALLOW_METHODS, "OPTIONS, POST"),)
            headers += cache_headers()
            return web.Response(status=204, headers=headers)

        # open sequence (sockjs protocol)
        resp = self.response = web.StreamResponse(headers=headers)
        resp.force_close()
        await resp.prepare(request)
        await resp.write(self.open_seq)

        # event loop
        await self.handle_session()

        return resp 
开发者ID:aio-libs,项目名称:sockjs,代码行数:28,代码来源:xhrstreaming.py

示例5: set_cors

# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_OPTIONS [as 别名]
def set_cors(self, app, *, domains='*', handler=None, headers=()):
        assert app.router is self, 'Application must be initialized ' \
                                   'with this instance router'
        self._domains = domains
        self._cors_headers = headers
        if self._default_options_route is None:
            app.on_response_prepare.append(self.cors_on_prepare)
            if handler is None:
                handler = self.cors_options
        if handler is not None:
            self._default_options_route = Route(
                hdrs.METH_OPTIONS, handler, self._resource) 
开发者ID:aamalev,项目名称:aiohttp_apiset,代码行数:14,代码来源:dispatcher.py

示例6: add_options

# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_OPTIONS [as 别名]
def add_options(
        self, path: str, handler: WebHandler, **kwargs: Any
    ) -> web.AbstractRoute:
        return self.add_route(hdrs.METH_OPTIONS, path, handler, **kwargs) 
开发者ID:hh-h,项目名称:aiohttp-swagger3,代码行数:6,代码来源:swagger.py

示例7: test_all_methods

# 需要导入模块: from aiohttp import hdrs [as 别名]
# 或者: from aiohttp.hdrs import METH_OPTIONS [as 别名]
def test_all_methods(swagger_docs, aiohttp_client):
    class View(web.View):
        async def get(self):
            """
            ---

            responses:
              '200':
                description: OK.

            """
            return web.json_response()

    async def handler(request):
        """
        ---

        responses:
          '200':
            description: OK.

        """
        return web.json_response()

    swagger = swagger_docs()
    swagger.add_get("/r", handler, allow_head=False),
    swagger.add_head("/r", handler),
    swagger.add_put("/r", handler),
    swagger.add_patch("/r", handler),
    swagger.add_post("/r", handler),
    swagger.add_delete("/r", handler),
    swagger.add_options("/r", handler),
    swagger.add_view("/r2", View),

    client = await aiohttp_client(swagger._app)

    for method in (
        hdrs.METH_GET,
        hdrs.METH_HEAD,
        hdrs.METH_POST,
        hdrs.METH_PUT,
        hdrs.METH_PATCH,
        hdrs.METH_DELETE,
        hdrs.METH_OPTIONS,
    ):
        resp = await getattr(client, method.lower())("/r")
        assert resp.status == 200

    resp = await client.get("/r2")
    assert resp.status == 200 
开发者ID:hh-h,项目名称:aiohttp-swagger3,代码行数:52,代码来源:test_methods.py


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