@@ -5,6 +5,7 @@ import (
55 "encoding/base64"
66 "errors"
77 "fmt"
8+ "html/template"
89 "io/ioutil"
910 "log"
1011 "net/http"
@@ -44,6 +45,7 @@ type OauthProxy struct {
4445 PassBasicAuth bool
4546 skipAuthRegex []string
4647 compiledRegex []*regexp.Regexp
48+ templates *template.Template
4749}
4850
4951func NewReverseProxy(target *url.URL) (proxy *httputil.ReverseProxy) {
@@ -103,6 +105,7 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
103105 skipAuthRegex: opts.SkipAuthRegex,
104106 compiledRegex: opts.CompiledRegex,
105107 PassBasicAuth: opts.PassBasicAuth,
108+ templates: loadTemplates(opts.CustomTemplatesDir),
106109 }
107110}
108111
@@ -245,7 +248,6 @@ func (p *OauthProxy) PingPage(rw http.ResponseWriter) {
245248func (p *OauthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, message string) {
246249 log.Printf("ErrorPage %d %s %s", code, title, message)
247250 rw.WriteHeader(code)
248− templates := getTemplates()
249251 t := struct {
250252 Title string
251253 Message string
@@ -253,13 +255,12 @@ func (p *OauthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, m
253255 Title: fmt.Sprintf("%d %s", code, title),
254256 Message: message,
255257 }
256− templates.ExecuteTemplate(rw, "error.html", t)
258+ p.templates.ExecuteTemplate(rw, "error.html", t)
257259}
258260
259261func (p *OauthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code int) {
260262 p.ClearCookie(rw, req)
261263 rw.WriteHeader(code)
262− templates := getTemplates()
263264
264265 t := struct {
265266 SignInMessage string
@@ -272,7 +273,7 @@ func (p *OauthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code
272273 Redirect: req.URL.RequestURI(),
273274 Version: VERSION,
274275 }
275− templates.ExecuteTemplate(rw, "sign_in.html", t)
276+ p.templates.ExecuteTemplate(rw, "sign_in.html", t)
276277}
277278
278279func (p *OauthProxy) ManualSignIn(rw http.ResponseWriter, req *http.Request) (string, bool) {