mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
add headers to HTTP Response objects and support for HTTP HEAD method
This commit is contained in:
parent
8b9bd1ca1c
commit
2e069fe1c7
4 changed files with 18 additions and 5 deletions
|
@ -63,7 +63,7 @@ class AiohttpSession(BaseSession):
|
||||||
raise err_cls(res.status, res.reason, res)
|
raise err_cls(res.status, res.reason, res)
|
||||||
|
|
||||||
body = await res.content.read()
|
body = await res.content.read()
|
||||||
return Response(body)
|
return Response(res.headers, body)
|
||||||
|
|
||||||
@atexit.register
|
@atexit.register
|
||||||
def cleanup():
|
def cleanup():
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# Copyright (c) 2019-2020 lilydjwg <lilydjwg@gmail.com>, et al.
|
# Copyright (c) 2019-2020 lilydjwg <lilydjwg@gmail.com>, et al.
|
||||||
|
|
||||||
import structlog
|
import structlog
|
||||||
from typing import Optional, Dict
|
from typing import Optional, Dict, Mapping
|
||||||
import json as _json
|
import json as _json
|
||||||
|
|
||||||
from ..ctxvars import tries, proxy, user_agent
|
from ..ctxvars import tries, proxy, user_agent
|
||||||
|
@ -14,8 +14,16 @@ class Response:
|
||||||
|
|
||||||
.. py:attribute:: body
|
.. py:attribute:: body
|
||||||
:type: bytes
|
:type: bytes
|
||||||
|
|
||||||
|
.. py:attribute:: headers
|
||||||
|
:type: Mapping[str, str]
|
||||||
'''
|
'''
|
||||||
def __init__(self, body):
|
def __init__(
|
||||||
|
self,
|
||||||
|
headers: Mapping[str, str],
|
||||||
|
body: bytes,
|
||||||
|
) -> None:
|
||||||
|
self.headers = headers
|
||||||
self.body = body
|
self.body = body
|
||||||
|
|
||||||
def json(self):
|
def json(self):
|
||||||
|
@ -31,6 +39,11 @@ class BaseSession:
|
||||||
) -> None:
|
) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
async def head(self, *args, **kwargs):
|
||||||
|
'''Shortcut for ``HEAD`` request.'''
|
||||||
|
return await self.request(
|
||||||
|
method='HEAD', *args, **kwargs)
|
||||||
|
|
||||||
async def get(self, *args, **kwargs):
|
async def get(self, *args, **kwargs):
|
||||||
'''Shortcut for ``GET`` request.'''
|
'''Shortcut for ``GET`` request.'''
|
||||||
return await self.request(
|
return await self.request(
|
||||||
|
|
|
@ -58,7 +58,7 @@ class HttpxSession(BaseSession):
|
||||||
raise TemporaryError(599, repr(e), e)
|
raise TemporaryError(599, repr(e), e)
|
||||||
|
|
||||||
body = await r.aread()
|
body = await r.aread()
|
||||||
return Response(body)
|
return Response(r.headers, body)
|
||||||
|
|
||||||
async def aclose(self):
|
async def aclose(self):
|
||||||
for client in self.clients.values():
|
for client in self.clients.values():
|
||||||
|
|
|
@ -84,6 +84,6 @@ class TornadoSession(BaseSession):
|
||||||
res.code, res.reason, res
|
res.code, res.reason, res
|
||||||
)
|
)
|
||||||
|
|
||||||
return Response(res.body)
|
return Response(res.headers, res.body)
|
||||||
|
|
||||||
session = TornadoSession()
|
session = TornadoSession()
|
||||||
|
|
Loading…
Add table
Reference in a new issue