mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-04-23 12:18:50 +02:00
Add new handler to redirect to HTTPS if flag is set
Signed-off-by: Josh Michielsen <github@mickey.dev>
This commit is contained in:
parent
e24e4ef880
commit
aae91b0ad6
10
http.go
10
http.go
@ -152,3 +152,13 @@ func (ln tcpKeepAliveListener) Accept() (c net.Conn, err error) {
|
|||||||
tc.SetKeepAlivePeriod(3 * time.Minute)
|
tc.SetKeepAlivePeriod(3 * time.Minute)
|
||||||
return tc, nil
|
return tc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func redirectToHTTPS(opts *Options, h http.Handler) http.Handler {
|
||||||
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if opts.ForceHTTPS {
|
||||||
|
http.Redirect(w, r, opts.HTTPSAddress, http.StatusPermanentRedirect)
|
||||||
|
}
|
||||||
|
|
||||||
|
h.ServeHTTP(w, r)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
4
main.go
4
main.go
@ -186,9 +186,9 @@ func main() {
|
|||||||
|
|
||||||
var handler http.Handler
|
var handler http.Handler
|
||||||
if opts.GCPHealthChecks {
|
if opts.GCPHealthChecks {
|
||||||
handler = gcpHealthcheck(LoggingHandler(oauthproxy))
|
handler = redirectToHTTPS(opts, gcpHealthcheck(LoggingHandler(oauthproxy)))
|
||||||
} else {
|
} else {
|
||||||
handler = LoggingHandler(oauthproxy)
|
handler = redirectToHTTPS(opts, LoggingHandler(oauthproxy))
|
||||||
}
|
}
|
||||||
s := &Server{
|
s := &Server{
|
||||||
Handler: handler,
|
Handler: handler,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user