FastAPI · Class
TrustedHostMiddleware
TrustedHostMiddleware checks request Host headers against allowed host names. It helps protect against HTTP Host Header attacks and returns 400 for invalid hosts.
Last updated
Syntax
TrustedHostMiddleware(app, allowed_hosts=None, www_redirect=True)In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.
SubscribeRelated
FastAPIHTTPSRedirectMiddlewareGZipMiddlewareCORSMiddlewareStarlette