Skip to main content

Setting up security-relevant response headers in FastAPI

Project description

bacinet

Helmet-like http response Headers for FastAPI.

This is alpha software lacking testing and proper documentation. Use at your own risk!

Basic usage

Install package via pip install bacinet.

In your code, import apply from the package and add it as a middleware to your app:

from bacinet import apply
from fastapi import FastAPI, Request

app = FastAPI()


@app.middleware("http")
async def add_bacinet(request: Request, call_next):
    response = await call_next(request)
    apply(response)
    return response

Alternatively, you can use an ASGI-conformant Middlware:

from bacinet import BacinetMiddleware


app = FastAPI()


app.add_middleware(BacinetMiddleware)

To change the default options, import and change the options dictionary from bacinet:

from bacinet import options

options["X-DNS-Prefetch-Control"] = "on"

You can also import individual header functions (like x_download_options) and apply those.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bacinet-0.0.4.tar.gz (4.9 kB view hashes)

Uploaded Source

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