cmd/golangorg: serve m.golang.org redirect

When we set up Gmail for golang.org a decade ago,
we also configured Gmail to serve m.golang.org as a shortcut
to redirect to the full Gmail URL for golang.org.
It still does, but only if you connect to http://m.golang.org/.

CL 122175 broke the m.golang.org redirect back in summer 2018
by setting an HSTS Strict-Transport-Security header with includeSubdomains,
so that visiting golang.org stops the browser from being willing to
visit http://m.golang.org/. It goes straight to https, which fails.

I have been annoyed for years that this was broken, but I wasn't sure
when it started and never took the time to track down what was wrong.

This CL fixes m.golang.org by serving the redirect ourselves.

Change-Id: I290bb2fe7fc7a415d00162776ecc54527e431c61
Reviewed-on: https://go-review.googlesource.com/c/website/+/341710
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Website-Publish: Russ Cox <rsc@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
diff --git a/cmd/golangorg/server.go b/cmd/golangorg/server.go
index 221e762..8b3398b 100644
--- a/cmd/golangorg/server.go
+++ b/cmd/golangorg/server.go
@@ -159,6 +159,12 @@
 		log.Fatalf("loading beta site: %v", err)
 	}
 
+	// m.golang.org is an old shortcut for golang.org mail.
+	// Gmail itself can serve this redirect, but only on HTTP (not HTTPS).
+	// Golang.org's HSTS header tells browsers to use HTTPS for all subdomains,
+	// which broke the redirect.
+	mux.Handle("m.golang.org/", redirectAll("https://mail.google.com/a/golang.org/"))
+
 	if !isTestBinary {
 		go watchTip(&tipGoroot)
 	}
@@ -603,3 +609,9 @@
 	}
 	return (*fsys).Open(name)
 }
+
+func redirectAll(url string) http.Handler {
+	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+		http.Redirect(w, r, url, http.StatusMovedPermanently)
+	})
+}
diff --git a/cmd/golangorg/testdata/web.txt b/cmd/golangorg/testdata/web.txt
index 8173793..76e919e 100644
--- a/cmd/golangorg/testdata/web.txt
+++ b/cmd/golangorg/testdata/web.txt
@@ -197,3 +197,9 @@
 body !contains []byte(&amp;#34;orders&amp;#34;)
 body contains <span class="comment">
 body !contains &lt;span class=&#34;comment&#34;&gt;
+
+GET https://m.golang.org/
+redirect == https://mail.google.com/a/golang.org/
+
+GET https://m.golang.org/anything
+redirect == https://mail.google.com/a/golang.org/