Skip to main content

No project description provided

Project description

asgi_headers

Simple middleware for injecting headers in ASGI apps.

Installation

The library is available on PyPI:

pip install asgi_headers

Or in the Releases tab, both in sdist format as well as wheels.

Supported Python versions

Currently the library supports Python 3.11 only.

Example usage:

With FastAPI

from fastapi import FastAPI
from asgi_headers import InjectHeadersMiddleware

app = FastAPI()
app.add_middleware(
    InjectHeadersMiddleware,
    injections={
        ("GET", "/hello"): {"This-Header-Will-Be-Injected-To-All-GET-Requests-Starting-With-/foo-path": 1},
        ("*", "/hello", "This-Header-Will-Be-Injected-To-All-Requests-Starting-With-/foo-path", "1")
        ("GET", "*", "This-Header-Will-Be-Injected-To-All-GET-Requests", "1")
        ("*", "*", "This-Header-Will-Be-Injected-To-All-Requests", "1")
    }
)

@app.get("/hello")
def hello_world():
    return {"hello": "world"}

With Litestar

from litestar import Litestar
from asgi_headers import InjectHeadersMiddlewareFactory

@get(path="/", media_type="application/json", sync_to_thread=False)
def hello_world() -> dict[str, str]:
    return {"hello": "world"}

app = Litestar(
    route_handlers=[hello_world],
    middleware=[
        InjectHeadersMiddlewareFactory(
            injections={
                ("GET", "/hello"): {"This-Header-Will-Be-Injected-To-All-GET-Requests-Starting-With-/foo-path": 1},
                ("*", "/hello", "This-Header-Will-Be-Injected-To-All-Requests-Starting-With-/foo-path", "1")
                ("GET", "*", "This-Header-Will-Be-Injected-To-All-GET-Requests", "1")
                ("*", "*", "This-Header-Will-Be-Injected-To-All-Requests", "1")
            }
        ),
    ]
)

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

asgi_headers-0.1.0.tar.gz (4.6 kB view hashes)

Uploaded Source

Built Distributions

asgi_headers-0.1.0-cp311-cp311-win_amd64.whl (55.0 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

asgi_headers-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (142.0 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64 manylinux: glibc 2.28+ x86-64

asgi_headers-0.1.0-cp311-cp311-macosx_10_9_universal2.whl (145.1 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

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