本文整理匯總了Python中aiohttp.hdrs.METH_HEAD屬性的典型用法代碼示例。如果您正苦於以下問題:Python hdrs.METH_HEAD屬性的具體用法?Python hdrs.METH_HEAD怎麽用?Python hdrs.METH_HEAD使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類aiohttp.hdrs
的用法示例。
在下文中一共展示了hdrs.METH_HEAD屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: head
# 需要導入模塊: from aiohttp import hdrs [as 別名]
# 或者: from aiohttp.hdrs import METH_HEAD [as 別名]
def head(path: str, **kwargs: Any) -> WebHandlerDecorator:
return handle(hdrs.METH_HEAD, path, **kwargs)
示例2: add_head
# 需要導入模塊: from aiohttp import hdrs [as 別名]
# 或者: from aiohttp.hdrs import METH_HEAD [as 別名]
def add_head(self, *args, **kwargs):
"""
Shortcut for add_route with method HEAD
"""
return self.add_route(hdrs.METH_HEAD, *args, **kwargs)
示例3: add_head
# 需要導入模塊: from aiohttp import hdrs [as 別名]
# 或者: from aiohttp.hdrs import METH_HEAD [as 別名]
def add_head(
self, path: str, handler: WebHandler, **kwargs: Any
) -> web.AbstractRoute:
return self.add_route(hdrs.METH_HEAD, path, handler, **kwargs)
示例4: add_get
# 需要導入模塊: from aiohttp import hdrs [as 別名]
# 或者: from aiohttp.hdrs import METH_HEAD [as 別名]
def add_get(
self,
path: str,
handler: WebHandler,
name: Optional[str] = None,
allow_head: bool = True,
**kwargs: Any,
) -> web.AbstractRoute:
if allow_head:
self.add_route(hdrs.METH_HEAD, path, handler, **kwargs)
return self.add_route(hdrs.METH_GET, path, handler, name=name, **kwargs)
示例5: _aiohttp_do_redirect
# 需要導入模塊: from aiohttp import hdrs [as 別名]
# 或者: from aiohttp.hdrs import METH_HEAD [as 別名]
def _aiohttp_do_redirect(session, method, url, headers, data, resp):
# This is the redirect code from aiohttp, remove once
# https://github.com/aio-libs/aiobotocore/issues/267 is supported
# For 301 and 302, mimic IE, now changed in RFC
# https://github.com/kennethreitz/requests/pull/269
if (resp.status == 303 and
resp.method != hdrs.METH_HEAD) \
or (resp.status in (301, 302) and
resp.method == hdrs.METH_POST):
method = hdrs.METH_GET
data = None
if headers.get(hdrs.CONTENT_LENGTH):
headers.pop(hdrs.CONTENT_LENGTH)
r_url = (resp.headers.get(hdrs.LOCATION) or
resp.headers.get(hdrs.URI))
if r_url is None:
return None
r_url = URL(
r_url, encoded=not session.requote_redirect_url)
scheme = r_url.scheme
if scheme not in ('http', 'https', ''):
resp.close()
raise ValueError(
'Can redirect only to http or https')
elif not scheme:
r_url = url.join(r_url)
url = r_url
params = None
resp.release()
return method, url, headers, params, data
示例6: test_all_methods
# 需要導入模塊: from aiohttp import hdrs [as 別名]
# 或者: from aiohttp.hdrs import METH_HEAD [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