1
0
mirror of https://github.com/golang/go synced 2024-09-30 16:08:36 -06:00

cmd/tip: redirect from HTTP to HTTPS; update to Go 1.6

Change-Id: I7b219a991df4f71d068b62a22f69acb123ac31f0
Reviewed-on: https://go-review.googlesource.com/22367
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Andrew Gerrand 2016-04-22 13:40:43 +10:00
parent 4e3242e000
commit 53006ac4c2
2 changed files with 19 additions and 3 deletions

View File

@ -1,4 +1,4 @@
FROM golang:1.5
FROM golang:1.6
RUN apt-get update && apt-get install --no-install-recommends -y -q build-essential git

View File

@ -44,7 +44,7 @@ func main() {
p := &Proxy{builder: b}
go p.run()
http.Handle("/", p)
http.Handle("/", httpsOnlyHandler{p})
http.HandleFunc("/_ah/health", p.serveHealthCheck)
log.Print("Starting up")
@ -323,3 +323,19 @@ func getOK(url string) (body []byte, err error) {
}
return body, nil
}
// httpsOnlyHandler redirects requests to "http://example.com/foo?bar"
// to "https://example.com/foo?bar"
type httpsOnlyHandler struct {
h http.Handler
}
func (h httpsOnlyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("X-Appengine-Https") == "off" {
r.URL.Scheme = "https"
r.URL.Host = r.Host
http.Redirect(w, r, r.URL.String(), http.StatusFound)
return
}
h.h.ServeHTTP(w, r)
}