Extract ProcessCookie() from ServeHTTP()

This commit is contained in:
Mike Bland 2015-05-08 10:09:47 -04:00
parent 26170c56af
commit 1bd90cefe7

View File

@ -270,6 +270,22 @@ func (p *OauthProxy) SetCookie(rw http.ResponseWriter, req *http.Request, val st
http.SetCookie(rw, cookie) http.SetCookie(rw, cookie)
} }
func (p *OauthProxy) ProcessCookie(rw http.ResponseWriter, req *http.Request) (email, user, access_token string, ok bool) {
cookie, err := req.Cookie(p.CookieKey)
if err == nil {
var value string
value, ok = validateCookie(cookie, p.CookieSeed)
if ok {
email, user, access_token, err = parseCookieValue(
value, p.AesCipher)
if err != nil {
log.Printf(err.Error())
}
}
}
return
}
func (p *OauthProxy) PingPage(rw http.ResponseWriter) { func (p *OauthProxy) PingPage(rw http.ResponseWriter) {
rw.WriteHeader(http.StatusOK) rw.WriteHeader(http.StatusOK)
fmt.Fprintf(rw, "OK") fmt.Fprintf(rw, "OK")
@ -440,18 +456,7 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
} }
if !ok { if !ok {
cookie, err := req.Cookie(p.CookieKey) email, user, access_token, ok = p.ProcessCookie(rw, req)
if err == nil {
var value string
value, ok = validateCookie(cookie, p.CookieSeed)
if ok {
email, user, access_token, err = parseCookieValue(
value, p.AesCipher)
if err != nil {
log.Printf(err.Error())
}
}
}
} }
if !ok { if !ok {