cmd/pomerium: redirect http and add hsts headers (#92)

This commit is contained in:
Bobby DeSimone 2019-04-24 13:29:11 -07:00 committed by GitHub
parent fbe1cae482
commit 857b9e5773
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 29 deletions

View file

@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"os"
"time"
"google.golang.org/grpc"
@ -102,6 +103,7 @@ func main() {
if proxyService != nil {
topMux.Handle("/", proxyService.Handler())
}
httpOpts := &https.Options{
Addr: mainOpts.Addr,
Cert: mainOpts.Cert,
@ -110,6 +112,18 @@ func main() {
KeyFile: mainOpts.KeyFile,
}
log.Fatal().Err(https.ListenAndServeTLS(httpOpts, topMux, grpcServer)).Msg("cmd/pomerium: https serve failure")
// redirect http to https
srv := &http.Server{
ReadTimeout: 5 * time.Second,
WriteTimeout: 5 * time.Second,
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Connection", "close")
url := fmt.Sprintf("https://%s%s", r.Host, r.URL.String())
http.Redirect(w, r, url, http.StatusMovedPermanently)
}),
}
go func() { log.Fatal().Err(srv.ListenAndServe()).Msg("cmd/pomerium: http server") }()
log.Fatal().Err(https.ListenAndServeTLS(httpOpts, topMux, grpcServer)).Msg("cmd/pomerium: https server")
}