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.

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 by default. Because it will delay sending the response until collected all its body and consumes more memory. You can enable it by setting streaming=True:

    app = FastAPI(middleware=[Middleware(ETagMiddleware, streaming=True)])
    

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.1.0-py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 3

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