cmd/golangorg: default to go.dev for testing server

When running server locally, requests for /foo redirect
to /golang.org/foo, and you can specify other hosts at the
start of the URL instead.

Preparing for the move to go.dev, redirect /foo to /go.dev/foo instead.
This just makes local development and testing a little nicer.
It doesn't have any effect on the actual server.

Change-Id: Iabc4186559cbf498f9b361060412702153859a6d
Reviewed-on: https://go-review.googlesource.com/c/website/+/362958
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
This commit is contained in:
Russ Cox 2021-11-09 22:52:37 -05:00
Родитель cecdbb6e8e
Коммит 7c7e6d209d
2 изменённых файлов: 4 добавлений и 4 удалений

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

@ -399,11 +399,11 @@ var validHosts = map[string]bool{
func hostEnforcerHandler(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
isHTTPS := r.TLS != nil || r.Header.Get("X-Forwarded-Proto") == "https" || r.URL.Scheme == "https"
defaultHost := "golang.org"
defaultHost := "go.dev"
host := strings.ToLower(r.Host)
isValidHost := validHosts[host]
if googleCN(r) && strings.HasSuffix(host, "golang.org") {
if googleCN(r) && !strings.HasSuffix(host, "google.cn") {
// golang.google.cn is the only web site in China.
defaultHost = "golang.google.cn"
isValidHost = strings.ToLower(r.Host) == defaultHost
@ -441,7 +441,7 @@ func hostPathHandler(h http.Handler) http.Handler {
elem, rest = elem[:i], elem[i+1:]
}
if !validHosts[elem] {
u := "/golang.org" + r.URL.EscapedPath()
u := "/go.dev" + r.URL.EscapedPath()
if r.URL.RawQuery != "" {
u += "?" + r.URL.RawQuery
}

2
cmd/golangorg/testdata/web.txt поставляемый
Просмотреть файл

@ -3,7 +3,7 @@ code == 301
redirect == https://go.dev/
GET http://localhost:6060/
redirect == /golang.org/
redirect == /go.dev/
GET http://localhost:6060/go.dev/
body contains Go is an open source programming language