ETag Middleware
A middleware to handle ETag for Starlette or FastAPI.
Installation
pip install etag-middleware
Usage
FastAPI
from etag import ETagMiddleware
from fastapi import FastAPI
from fastapi.middleware import Middleware
app = FastAPI(middleware=[Middleware(ETagMiddleware)])
Starlette
from etag import ETagMiddleware
from starlette.applications import Starlette
from starlette.middleware import Middleware
app = Starlette(middleware=[Middleware(ETagMiddleware)])
Notice
-
It won't compute
ETagfor requests with body size less than 80 bytes by default. BeacauseETagandIf-None-Matchincrease more than 70 bytes to the response header, and computingETagconsumes CPU. You can adjust it by settingminimum_size:app = FastAPI(middleware=[Middleware(ETagMiddleware, minimum_size=0)])
-
It won't compute
ETagforStreamingResponse. Because it will delay sending the response until collected all its body and consumes more memory. -
It compares
ETagwithIf-None-MatchforFileResponse.
Metadata
Release files for etag-middleware 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| etag_middleware-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Release files / etag_middleware-0.2.0-py3-none-any.whl
| Download URL | etag_middleware-0.2.0-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aee4dd0cb9da4e15134f2d8045b964dd17062b27bb1797bd09a87232ded5c34d
|
|
BLAKE2b-256 checksum How to use checksums |
6f5d9c168012b9441826666bc25d3f3a378fc0f1fd1c5d7d2117c6ed6c50a13a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.3
|