feat(rpc): support the If-None-Match request header

If the If-None-Match header is supplied with a previously
obtained ETag from the same query, a 304 Not Modified is
returned with no content.

This allows clients to completely leverage the ETag header.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-10-31 01:22:54 -07:00
parent 2cc44e8f28
commit 61f3cb938c
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
2 changed files with 15 additions and 2 deletions

View file

@ -113,6 +113,11 @@ async def rpc(request: Request,
"ETag": f'"{etag}"'
}
if_none_match = request.headers.get("If-None-Match", str())
if if_none_match and if_none_match.strip("\t\n\r\" ") == etag:
return Response(headers=headers,
status_code=int(HTTPStatus.NOT_MODIFIED))
if callback:
content = f"/**/{callback}({content.decode()})"