A middleware to handle ETag for Starletter or FastAPI.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file etag_middleware-0.2.0-py3-none-any.whl.
File metadata
- Download URL: etag_middleware-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aee4dd0cb9da4e15134f2d8045b964dd17062b27bb1797bd09a87232ded5c34d
|
|
| MD5 |
5ea372812f17f6bfc007d42c95c78734
|
|
| BLAKE2b-256 |
6f5d9c168012b9441826666bc25d3f3a378fc0f1fd1c5d7d2117c6ed6c50a13a
|