Skip to content

Commit 8c74b73

Browse files
committed
cmd/tip: use proxy.golang.org when building x/website
The new x/website is built in module mode. Now that proxy.golang.org is available publicly, cmd/tip can start using it for fetching modules when building x/website. Also make a change to newServeMux so that httpsOnlyHandler is only used when HTTPS is turned on. That stops redirecting to HTTPS when HTTPS is not being served, thereby fixing HTTP-only local development mode. Updates golang/go#26872 Updates golang/go#30232 Updates golang/go#29206 Change-Id: If0382c45b9c99540adce3a894054730f5a7a9fdb Reviewed-on: https://go-review.googlesource.com/c/build/+/177217 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 95bc93b commit 8c74b73

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

cmd/tip/golangorg.go

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func (b golangorgBuilder) Init(logger *log.Logger, dir, hostport string, heads m
6060
install.Env = append(os.Environ(),
6161
"GOROOT="+goDir,
6262
"GO111MODULE=on",
63+
"GOPROXY=https://proxy.golang.org",
6364
"GOBIN="+binDir,
6465
)
6566
if err := install.Run(); err != nil {

cmd/tip/tip.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ func main() {
5656

5757
p := &Proxy{builder: b}
5858
go p.run()
59-
mux := newServeMux(p)
59+
mux := newServeMux(p, serveOptions{
60+
// Redirect to HTTPS only if we're actually serving HTTPS.
61+
RedirectToHTTPS: *autoCertDomain != "",
62+
})
6063

6164
log.Printf("Starting up tip server for builder %q", os.Getenv(k))
6265

@@ -253,9 +256,19 @@ func (p *Proxy) poll() {
253256
p.cmd = cmd
254257
}
255258

256-
func newServeMux(p *Proxy) http.Handler {
259+
type serveOptions struct {
260+
// RedirectToHTTPS controls whether requests served
261+
// over HTTP should be redirected to HTTPS.
262+
RedirectToHTTPS bool
263+
}
264+
265+
func newServeMux(p *Proxy, opt serveOptions) http.Handler {
257266
mux := http.NewServeMux()
258-
mux.Handle("/", httpsOnlyHandler{p})
267+
if opt.RedirectToHTTPS {
268+
mux.Handle("/", httpsOnlyHandler{p})
269+
} else {
270+
mux.Handle("/", p)
271+
}
259272
mux.HandleFunc("/_ah/health", p.serveHealthCheck)
260273
return mux
261274
}

cmd/tip/tip_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
func TestTipRedirects(t *testing.T) {
13-
mux := newServeMux(&Proxy{builder: &golangorgBuilder{}})
13+
mux := newServeMux(&Proxy{builder: &golangorgBuilder{}}, serveOptions{RedirectToHTTPS: true})
1414
req := httptest.NewRequest("GET", "http://example.com/foo?bar=baz", nil)
1515
req.Header.Set("X-Forwarded-Proto", "http")
1616
w := httptest.NewRecorder()

0 commit comments

Comments
 (0)