Skip to content

joeraad/header-propagation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Header Propagation Middleware

Middleware for propagating headers from incoming requests to outgoing requests for FastAPI.

Installation

pip install header-propagation-middleware

Setup

To setup the middleware, you need to add it to your FastAPI app.

Adding Middleware

from header_propagation_middleware import HeaderPropagationMiddleware

app = FastAPI()
app.add_middleware(HeaderPropagationMiddleware,header_names=["header1","header2"])

Configurable middleware argument

header_names

  • Type: List[str]
  • Default: []
  • Description: The list of headers to propagate.

Accessing propagated headers

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.

Tests

Running test

python -m pytest

Running test with coverage report

python -m pytest --cov --cov-report=html:reports/html_dir