cmd/golangorg: add blog to valid hosts

Also hard-code EnforceHosts behavior.
It was only optional to enable the old tip.golang.org server,
but that code is dead or at least no longer pointed to by DNS.

Hard-coding the EnforceHosts behavior makes for fewer
prod-only test failures.

Change-Id: Ib958b3f088c8175e67708efcd07426b9628b207b
Reviewed-on: https://go-review.googlesource.com/c/website/+/343311
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
Russ Cox 2021-08-18 16:01:02 -04:00
Родитель 6c6d3e7c40
Коммит b110cf7979
2 изменённых файлов: 7 добавлений и 16 удалений

Просмотреть файл

@ -35,7 +35,6 @@ import (
"golang.org/x/website/internal/backport/osfs"
"golang.org/x/website/internal/codewalk"
"golang.org/x/website/internal/dl"
"golang.org/x/website/internal/env"
"golang.org/x/website/internal/gitfs"
"golang.org/x/website/internal/history"
"golang.org/x/website/internal/memcache"
@ -211,9 +210,7 @@ func NewHandler(contentDir, goroot string) http.Handler {
mux.Handle("learn.go.dev/", redirectPrefix("https://go.dev/learn/"))
var h http.Handler = mux
if env.EnforceHosts() {
h = hostEnforcerHandler(h)
}
h = hostEnforcerHandler(h)
h = hostPathHandler(h)
return h
}
@ -362,13 +359,15 @@ func fmtHandler(w http.ResponseWriter, r *http.Request) {
}
var validHosts = map[string]bool{
"go.dev": true,
"learn.go.dev": true,
"golang.org": true,
"golang.google.cn": true,
"beta.golang.org": true,
"blog.golang.org": true,
"m.golang.org": true,
"tip.golang.org": true,
"beta.golang.org": true,
"go.dev": true,
"learn.go.dev": true,
}
// hostEnforcerHandler redirects http://foo.golang.org/bar to https://golang.org/bar.

10
internal/env/env.go поставляемый
Просмотреть файл

@ -12,10 +12,7 @@ import (
"strconv"
)
var (
enforceHosts = boolEnv("GOLANGORG_ENFORCE_HOSTS")
requireDLSecretKey = boolEnv("GOLANGORG_REQUIRE_DL_SECRET_KEY")
)
var requireDLSecretKey = boolEnv("GOLANGORG_REQUIRE_DL_SECRET_KEY")
// RequireDLSecretKey reports whether the download server secret key
// is expected to already exist, and the download server should panic
@ -24,11 +21,6 @@ func RequireDLSecretKey() bool {
return requireDLSecretKey
}
// EnforceHosts reports whether host filtering should be enforced.
func EnforceHosts() bool {
return enforceHosts
}
func boolEnv(key string) bool {
v := os.Getenv(key)
if v == "" {