Middleware for fastapi allowing it to respect X-Forwarded-... headers set by proxies.
Project description
HTTP Proxy Header support for FastAPI
This Python package allows transparent use of FastAPI-based solutions behind
proxies which set X-Forwarded-...
headers. Applications will construct URLs
based on those headers rather than the incoming Host
header.
Use
Install fastapi-proxiedheadersmiddleware
using pip:
pip install fastapi-proxiedheadersmiddleware
The module can then be used as fastapi_proxiedheadersmiddleware
when creating
your FastAPI app:
from fastapi import FastAPI
from fastapi_proxiedheadersmiddleware import ProxiedHeadersMiddleware
app = FastAPI()
app.add_middleware(ProxiedHeadersMiddleware)
The middleware respects the various X-Forwarded-...
headers and updates the
Host
header to match.
Developer quickstart
This project contains a dockerized testing environment which wraps tox.
Tests can be run using the ./test.sh
command:
# Run all PyTest tests and Flake8 checks
$ ./test.sh
# Run just PyTest
$ ./test.sh -e py3
# Run a single test file within PyTest
$ ./test.sh -e py3 -- tests/test_identifiers.py
# Run a single test file within PyTest with verbose logging
$ ./test.sh -e py3 -- tests/test_identifiers.py -vvv
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
Built Distribution
Hashes for fastapi-proxiedheadersmiddleware-0.9.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5672f68cef03181b92d24aa5894c903dd0ac630f6781cfb148dee1f18eca1e38 |
|
MD5 | 9f1e9f6732dde70f8fa1df965f22d363 |
|
BLAKE2b-256 | c974c899454e283c9d47c9b3d37fa81f9b6adb8201d80a0e5b7ae5f342b01ac5 |
Hashes for fastapi_proxiedheadersmiddleware-0.9.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31b02e1321fc5bdd51c9f2dc60ca36ae1c7637a2fbad496eb34eb17483c260ea |
|
MD5 | 723882d1b7040ddcfe350dd6b4bcd1ad |
|
BLAKE2b-256 | 9e254be86a78e172137362334e7171fa3bd5214b7c46a6772091111bc6968871 |