Skip to main content

A middleware to handle ETag for Starletter or FastAPI.

Project description

ETag Middleware

Build Status Coverage

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

  1. It won't compute ETag for requests with body size less than 80 bytes by default. Beacause ETag and If-None-Match increase more than 70 bytes to the response header, and computing ETag consumes CPU. You can adjust it by setting minimum_size:

    app = FastAPI(middleware=[Middleware(ETagMiddleware, minimum_size=0)])
    
  2. It won't compute ETag for StreamingResponse. Because it will delay sending the response until collected all its body and consumes more memory.

  3. It compares ETag with If-None-Match for FileResponse.

Project details


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

etag_middleware-0.2.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file etag_middleware-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for etag_middleware-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aee4dd0cb9da4e15134f2d8045b964dd17062b27bb1797bd09a87232ded5c34d
MD5 5ea372812f17f6bfc007d42c95c78734
BLAKE2b-256 6f5d9c168012b9441826666bc25d3f3a378fc0f1fd1c5d7d2117c6ed6c50a13a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page