kopia lustrzana https://github.com/jointakahe/takahe
Porównaj commity
2 Commity
1dec02f89c
...
e46992448d
Autor | SHA1 | Data |
---|---|---|
Jamie Bliss | e46992448d | |
Jamie Bliss | 3c6820cfe3 |
|
@ -141,18 +141,28 @@ class IpFilterWrapperTransport(httpx.BaseTransport, httpx.AsyncBaseTransport):
|
|||
# misconfigured or malicious
|
||||
|
||||
def handle_request(self, request: httpx.Request) -> httpx.Response:
|
||||
self._check_addrinfo(
|
||||
request, socket.getaddrinfo(*self._request_to_addrinfo(request))
|
||||
)
|
||||
try:
|
||||
self._check_addrinfo(
|
||||
request, socket.getaddrinfo(*self._request_to_addrinfo(request))
|
||||
)
|
||||
except socket.gaierror:
|
||||
# Some kind of look up error. Gonna assume safe and let farther
|
||||
# down the stack handle it.
|
||||
pass
|
||||
return self.wrappee.handle_request(request)
|
||||
|
||||
async def handle_async_request(self, request: httpx.Request) -> httpx.Response:
|
||||
self._check_addrinfo(
|
||||
request,
|
||||
await asyncio.get_running_loop().getaddrinfo(
|
||||
*self._request_to_addrinfo(request)
|
||||
),
|
||||
)
|
||||
try:
|
||||
self._check_addrinfo(
|
||||
request,
|
||||
await asyncio.get_running_loop().getaddrinfo(
|
||||
*self._request_to_addrinfo(request)
|
||||
),
|
||||
)
|
||||
except socket.gaierror:
|
||||
# Some kind of look up error. Gonna assume safe and let farther
|
||||
# down the stack handle it.
|
||||
pass
|
||||
return await self.wrappee.handle_await_request(request)
|
||||
|
||||
|
||||
|
|
|
@ -69,6 +69,16 @@ class HttpSignature:
|
|||
Allows for calculation and verification of HTTP signatures
|
||||
"""
|
||||
|
||||
#: Headers we should consider when producing signatures
|
||||
HEADERS_FOR_SIGNING = {
|
||||
"date",
|
||||
"host",
|
||||
"(request-target)",
|
||||
"content-type",
|
||||
"content-length",
|
||||
"digest",
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def calculate_digest(cls, data, algorithm="sha-256") -> str:
|
||||
"""
|
||||
|
@ -211,7 +221,9 @@ class HttpSignature:
|
|||
|
||||
# Sign the headers
|
||||
signing_headers = [
|
||||
key for key in request.headers.keys() if key.lower() != "user-agent"
|
||||
key
|
||||
for key in request.headers.keys()
|
||||
if key.lower() in cls.HEADERS_FOR_SIGNING
|
||||
]
|
||||
signed_string = "\n".join(
|
||||
f"{name.lower()}: {value}"
|
||||
|
|
Ładowanie…
Reference in New Issue