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