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.0.tar.gz
(4.6 kB
view hashes)
Built Distributions
Close
Hashes for asgi_headers-0.1.0-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ec50bd7f0fb9357242af5c036f6c0caba6dc9cbec4d952f4b820c1835f9e7ad |
|
MD5 | 92f4dfa99961be3fd045ba31a93c4d8f |
|
BLAKE2b-256 | 1511369d6d85238bfbdeb9df76707e15265712a77ab566b171f4162efd848686 |
Close
Hashes for asgi_headers-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 336bd8530565d545f31b12d69b2907ff4012ef38283e08ec152a72cf62fba51f |
|
MD5 | 2678cbac44eab38e480d8ea919956df6 |
|
BLAKE2b-256 | c75c2fcae405dc3f5b0e9c4ffa877ecf90fb56fff943c6da87a6d428df132ee4 |
Close
Hashes for asgi_headers-0.1.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be7eb27386aea1c8db4c4b82f469af65eeab37cc17da84459eba96af8ecd68fb |
|
MD5 | caf1cac8156f1a844a5b420e04667f26 |
|
BLAKE2b-256 | c0edcdd812caa44581d09f30e3c7f61320bb63b2d9054da78364b076b6899838 |