git.iko.soy/typeable/oauth2-proxy
on master help sign in
Add new handler to redirect to HTTPS if flag is set

Signed-off-by: Josh Michielsen <github@mickey.dev>

commitaae91b0ad6cddae6d7ea17085f4713567aba248a authorJosh Michielsen <github@mickey.dev> dateThu 17 Oct 2019, 16:30 (7 years ago) parente24e4ef
2 files changed+12−2
http.go+10 main.go+2−2
http.go+10
@@ -152,3 +152,13 @@ func (ln tcpKeepAliveListener) Accept() (c net.Conn, err error) {
152152 tc.SetKeepAlivePeriod(3 * time.Minute)
153153 return tc, nil
154154}
155+
156+func redirectToHTTPS(opts *Options, h http.Handler) http.Handler {
157+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
158+ if opts.ForceHTTPS {
159+ http.Redirect(w, r, opts.HTTPSAddress, http.StatusPermanentRedirect)
160+ }
161+
162+ h.ServeHTTP(w, r)
163+ })
164+}
main.go+2−2
@@ -186,9 +186,9 @@ func main() {
186186
187187 var handler http.Handler
188188 if opts.GCPHealthChecks {
189− handler = gcpHealthcheck(LoggingHandler(oauthproxy))
189+ handler = redirectToHTTPS(opts, gcpHealthcheck(LoggingHandler(oauthproxy)))
190190 } else {
191− handler = LoggingHandler(oauthproxy)
191+ handler = redirectToHTTPS(opts, LoggingHandler(oauthproxy))
192192 }
193193 s := &Server{
194194 Handler: handler,