git.iko.soy/typeable/oauth2-proxy
on master help sign in
Add new handler to redirect to HTTPS if flag is set
aae91b0Josh Michielsen
@@ -152,3 +152,13 @@ func (ln tcpKeepAliveListener) Accept() (c net.Conn, err error) {
152 tc.SetKeepAlivePeriod(3 * time.Minute)
152 tc.SetKeepAlivePeriod(3 * time.Minute)
153 return tc, nil
153 return tc, nil
154}
154}
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() {
186
186
187 var handler http.Handler
187 var handler http.Handler
188 if opts.GCPHealthChecks {
188 if opts.GCPHealthChecks {
189− handler = gcpHealthcheck(LoggingHandler(oauthproxy))
189+ handler = redirectToHTTPS(opts, gcpHealthcheck(LoggingHandler(oauthproxy)))
190 } else {
190 } else {
191− handler = LoggingHandler(oauthproxy)
191+ handler = redirectToHTTPS(opts, LoggingHandler(oauthproxy))
192 }
192 }
193 s := &Server{
193 s := &Server{
194 Handler: handler,
194 Handler: handler,