Middleware for propagating headers from incoming requests to outgoing requests for FastAPI.
pip install header-propagation-middleware
To setup the middleware, you need to add it to your FastAPI app.
from header_propagation_middleware import HeaderPropagationMiddleware
app = FastAPI()
app.add_middleware(HeaderPropagationMiddleware,header_names=["header1","header2"])
header_names
- Type:
List[str]
- Default:
[]
- Description: The list of headers to propagate.
You can access the propagated headers using the propagated_headers
object.
from header_propagation_middleware import propagated_headers
propagated_headers.get()
propagated_headers
- Type:
dict
- Default:
{}
- Description: The dictionary of propagated headers.
Running test
python -m pytest
Running test with coverage report
python -m pytest --cov --cov-report=html:reports/html_dir