Skip to content

Commit

Permalink
cmd/tip: use proxy.golang.org when building x/website
Browse files Browse the repository at this point in the history
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 <bradfitz@golang.org>
  • Loading branch information
dmitshur committed May 14, 2019
1 parent 95bc93b commit 8c74b73
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions cmd/tip/golangorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (b golangorgBuilder) Init(logger *log.Logger, dir, hostport string, heads m
install.Env = append(os.Environ(),
"GOROOT="+goDir,
"GO111MODULE=on",
"GOPROXY=https://proxy.golang.org",
"GOBIN="+binDir,
)
if err := install.Run(); err != nil {
Expand Down
19 changes: 16 additions & 3 deletions cmd/tip/tip.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ func main() {

p := &Proxy{builder: b}
go p.run()
mux := newServeMux(p)
mux := newServeMux(p, serveOptions{
// Redirect to HTTPS only if we're actually serving HTTPS.
RedirectToHTTPS: *autoCertDomain != "",
})

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

Expand Down Expand Up @@ -253,9 +256,19 @@ func (p *Proxy) poll() {
p.cmd = cmd
}

func newServeMux(p *Proxy) http.Handler {
type serveOptions struct {
// RedirectToHTTPS controls whether requests served
// over HTTP should be redirected to HTTPS.
RedirectToHTTPS bool
}

func newServeMux(p *Proxy, opt serveOptions) http.Handler {
mux := http.NewServeMux()
mux.Handle("/", httpsOnlyHandler{p})
if opt.RedirectToHTTPS {
mux.Handle("/", httpsOnlyHandler{p})
} else {
mux.Handle("/", p)
}
mux.HandleFunc("/_ah/health", p.serveHealthCheck)
return mux
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/tip/tip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

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

0 comments on commit 8c74b73

Please sign in to comment.