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
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 Distribution
asgi_headers-0.1.1.tar.gz
(4.6 kB
view hashes)
Built Distributions
Close
Hashes for asgi_headers-0.1.1-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 448bcf194b24b43a87a4457ff19242b518d0a1d28057d9b3959075d6d83f9432 |
|
MD5 | 261b1f90d6fca8f1575804d7da68a4e5 |
|
BLAKE2b-256 | cfbe6a611c30a5e7d98071862bd861fddf67fb81b22f21fd8ba6b5d48417f659 |
Close
Hashes for asgi_headers-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f4d0584a2a6e3e67ee0b098a025e3b3aee519e44abec0e0426fd5bc8a16a0a3 |
|
MD5 | 7c5ccf431b7ea19c9f92078418093798 |
|
BLAKE2b-256 | 2772989e1820d125a14261c2c5c0b91e00e7fb458194f5c1c7de896a5f1e2ef3 |
Close
Hashes for asgi_headers-0.1.1-cp312-cp312-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0468078d62e1d1ece9d07005d77e8c8045265f5a8f9a064a548e12ea40695d37 |
|
MD5 | ec5085b4e38df1a0544a85f663e2167c |
|
BLAKE2b-256 | 6d46417ef8be064670d8b9bf7d27ba256ae15dbcbad0f1bd912de0fa19b299c8 |
Close
Hashes for asgi_headers-0.1.1-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0bccbcd9a93ea22cc44078a92697fef173f25f125ac1b1eef2e85f3d9223666 |
|
MD5 | 2ea31a6be09663c84e75612089a96325 |
|
BLAKE2b-256 | 1a7811d90c59865aabb551b9a8f94d8a97e95cfb52285b17c51fd71d9b50fb9c |
Close
Hashes for asgi_headers-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c159ad9ee7f06d6f508fa9d428c6676e0084338a1a61e71201350f3796173b2 |
|
MD5 | e9aaca3f9155091ccd2991531a885c29 |
|
BLAKE2b-256 | 165a635028df397dc6769cfbad21eb19a50ce287345f2aeeabd8a24f96b2b756 |
Close
Hashes for asgi_headers-0.1.1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e398d293634a324715fa3a54572ddd18ce3a210ed4386f9f936154cc3066dcf |
|
MD5 | 50baef64836cf7f2047a773b56ffd6a2 |
|
BLAKE2b-256 | 407157270ed264d0936676f8df894754c5c9a53cf1735e19dd59a38f6cd9ee7e |