Files
fastapi/docs/en/docs/reference/middleware.md
Motov Yurii dc3278654f 📝 Use WSGIMiddleware from a2wsgi instead of deprecated fastapi.middleware.wsgi.WSGIMiddleware (#14756)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-02-04 12:54:23 +01:00

845 B

Middleware

There are several middlewares available provided by Starlette directly.

Read more about them in the FastAPI docs for Middleware.

::: fastapi.middleware.cors.CORSMiddleware

It can be imported from fastapi:

from fastapi.middleware.cors import CORSMiddleware

::: fastapi.middleware.gzip.GZipMiddleware

It can be imported from fastapi:

from fastapi.middleware.gzip import GZipMiddleware

::: fastapi.middleware.httpsredirect.HTTPSRedirectMiddleware

It can be imported from fastapi:

from fastapi.middleware.httpsredirect import HTTPSRedirectMiddleware

::: fastapi.middleware.trustedhost.TrustedHostMiddleware

It can be imported from fastapi:

from fastapi.middleware.trustedhost import TrustedHostMiddleware