Skip to main content

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.


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()

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 ./ command:

# Run all PyTest tests and Flake8 checks
$ ./

# Run just PyTest
$ ./ -e py3

# Run a single test file within PyTest
$ ./ -e py3 -- tests/

# Run a single test file within PyTest with verbose logging
$ ./ -e py3 -- tests/ -vvv

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

Built Distribution

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