mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-02-11 13:53:07 +02:00
render error page on 502 proxy status (#574)
Co-authored-by: Amnay Mokhtari <amnay.mokhtari@adevinta.com>
This commit is contained in:
parent
810a9e9967
commit
0c9795a964
@ -46,6 +46,7 @@
|
||||
|
||||
## Changes since v5.1.1
|
||||
|
||||
- [#574](https://github.com/oauth2-proxy/oauth2-proxy/pull/574) render error page on 502 proxy status (@amnay-mo)
|
||||
- [#559](https://github.com/oauth2-proxy/oauth2-proxy/pull/559) Rename cookie-domain config to cookie-domains (@JoelSpeed)
|
||||
- [#569](https://github.com/oauth2-proxy/oauth2-proxy/pull/569) Updated autocompletion for `--` long options. (@Izzette)
|
||||
- [#489](https://github.com/oauth2-proxy/oauth2-proxy/pull/489) Move Options and Validation to separate packages (@JoelSpeed)
|
||||
|
@ -154,9 +154,28 @@ func NewReverseProxy(target *url.URL, opts *options.Options) (proxy *httputil.Re
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}
|
||||
}
|
||||
setProxyErrorHandler(proxy, opts)
|
||||
return proxy
|
||||
}
|
||||
|
||||
func setProxyErrorHandler(proxy *httputil.ReverseProxy, opts *options.Options) {
|
||||
templates := loadTemplates(opts.CustomTemplatesDir)
|
||||
proxy.ErrorHandler = func(w http.ResponseWriter, r *http.Request, proxyErr error) {
|
||||
logger.Printf("Error proxying to upstream server: %v", proxyErr)
|
||||
w.WriteHeader(http.StatusBadGateway)
|
||||
data := struct {
|
||||
Title string
|
||||
Message string
|
||||
ProxyPrefix string
|
||||
}{
|
||||
Title: "Bad Gateway",
|
||||
Message: "Error proxying to upstream server",
|
||||
ProxyPrefix: opts.ProxyPrefix,
|
||||
}
|
||||
templates.ExecuteTemplate(w, "error.html", data)
|
||||
}
|
||||
}
|
||||
|
||||
func setProxyUpstreamHostHeader(proxy *httputil.ReverseProxy, target *url.URL) {
|
||||
director := proxy.Director
|
||||
proxy.Director = func(req *http.Request) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user