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.

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


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

File details

Details for the file fastapi-proxiedheadersmiddleware-0.9.0.tar.gz.

File metadata

  • Download URL: fastapi-proxiedheadersmiddleware-0.9.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7

File hashes

Hashes for fastapi-proxiedheadersmiddleware-0.9.0.tar.gz
Algorithm Hash digest
SHA256 5672f68cef03181b92d24aa5894c903dd0ac630f6781cfb148dee1f18eca1e38
MD5 9f1e9f6732dde70f8fa1df965f22d363
BLAKE2b-256 c974c899454e283c9d47c9b3d37fa81f9b6adb8201d80a0e5b7ae5f342b01ac5

See more details on using hashes here.

File details

Details for the file fastapi_proxiedheadersmiddleware-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: fastapi_proxiedheadersmiddleware-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7

File hashes

Hashes for fastapi_proxiedheadersmiddleware-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 31b02e1321fc5bdd51c9f2dc60ca36ae1c7637a2fbad496eb34eb17483c260ea
MD5 723882d1b7040ddcfe350dd6b4bcd1ad
BLAKE2b-256 9e254be86a78e172137362334e7171fa3bd5214b7c46a6772091111bc6968871

See more details on using hashes here.

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