From c94e31fdb0cf2c04635263ba46a22989df3aafbc Mon Sep 17 00:00:00 2001 From: Soul Lee Date: Mon, 15 Apr 2024 20:32:12 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=93=9D=20Add=20'www=5Fredirect'=20arg?= =?UTF-8?q?ument=20in=20TrustedHostMiddleware=20docs=20to=20reflect=20its?= =?UTF-8?q?=20presence=20in=20the=20code.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/advanced/middleware.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/advanced/middleware.md b/docs/en/docs/advanced/middleware.md index 9219f1d2c..f45c5b959 100644 --- a/docs/en/docs/advanced/middleware.md +++ b/docs/en/docs/advanced/middleware.md @@ -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. From 89d6a089aedf2074d43d7f278743c4b000928367 Mon Sep 17 00:00:00 2001 From: Soul Lee Date: Mon, 15 Apr 2024 20:43:37 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9DAdd=20'www=5Fredirect'=20in=20T?= =?UTF-8?q?rustedHostMiddleware=20tutorial.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs_src/advanced_middleware/tutorial002.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs_src/advanced_middleware/tutorial002.py b/docs_src/advanced_middleware/tutorial002.py index 405235ab9..302b5e81a 100644 --- a/docs_src/advanced_middleware/tutorial002.py +++ b/docs_src/advanced_middleware/tutorial002.py @@ -4,7 +4,7 @@ from fastapi.middleware.trustedhost import TrustedHostMiddleware app = FastAPI() app.add_middleware( - TrustedHostMiddleware, allowed_hosts=["example.com", "*.example.com"] + TrustedHostMiddleware, allowed_hosts=["example.com", "*.example.com"], www_redirect=True ) From ba3d6938e156ef55064b9fd6d24e75aeb127b3d0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 15 Apr 2024 11:44:15 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=8E=A8=20[pre-commit.ci]=20Auto=20for?= =?UTF-8?q?mat=20from=20pre-commit.com=20hooks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs_src/advanced_middleware/tutorial002.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs_src/advanced_middleware/tutorial002.py b/docs_src/advanced_middleware/tutorial002.py index 302b5e81a..0b2ca7394 100644 --- a/docs_src/advanced_middleware/tutorial002.py +++ b/docs_src/advanced_middleware/tutorial002.py @@ -4,7 +4,9 @@ from fastapi.middleware.trustedhost import TrustedHostMiddleware app = FastAPI() app.add_middleware( - TrustedHostMiddleware, allowed_hosts=["example.com", "*.example.com"], www_redirect=True + TrustedHostMiddleware, + allowed_hosts=["example.com", "*.example.com"], + www_redirect=True, )