Skip to content
Discussion options

You must be logged in to vote

Remove from main import app and @app.middleware("http") from demo_middleware module, then import your middleware to the main module and add middleware to the stack using

app.middleware("http")(demo_middleware.add_process_time_header)

or

app.add_middleware(BaseHTTPMiddleware, dispatch=demo_middleware.add_process_time_header)

Another way is to convert your middleware into the pure ASGI middleware and add it using app.add_middleware(YourMiddlewareClass)

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
3 participants