mirror of
https://github.com/golang/go
synced 2024-11-18 10:04:43 -07: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:
parent
4e3242e000
commit
53006ac4c2
@ -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
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user