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
ETag
for requests with body size less than 80 bytes by default. BeacauseETag
andIf-None-Match
increase more than 70 bytes to the response header, and computingETag
consumes CPU. You can adjust it by settingminimum_size
:app = FastAPI(middleware=[Middleware(ETagMiddleware, minimum_size=0)])
-
It won't compute
ETag
forStreamingResponse
. Because it will delay sending the response until collected all its body and consumes more memory. -
It compares
ETag
withIf-None-Match
forFileResponse
.
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
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
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 |