Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📝 Update TrustedHostMiddleware Documentation #11441

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/en/docs/advanced/middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Enforces that all incoming requests have a correctly set `Host` header, in order
The following arguments are supported:

* `allowed_hosts` - A list of domain names that should be allowed as hostnames. Wildcard domains such as `*.example.com` are supported for matching subdomains. To allow any hostname either use `allowed_hosts=["*"]` or omit the middleware.
* `www_redirect` - If set to True, requests to non-www versions of the allowed hosts will be redirected to their www counterparts. Defaults to `True`.

If an incoming request does not validate correctly then a `400` response will be sent.

Expand Down
4 changes: 3 additions & 1 deletion docs_src/advanced_middleware/tutorial002.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
app = FastAPI()

app.add_middleware(
TrustedHostMiddleware, allowed_hosts=["example.com", "*.example.com"]
TrustedHostMiddleware,
allowed_hosts=["example.com", "*.example.com"],
www_redirect=True,
)


Expand Down