From 32e71512ab0222922940d178e54f26d2bcc4fdea Mon Sep 17 00:00:00 2001 From: Joe Chen Date: Mon, 25 Nov 2024 21:26:31 -0500 Subject: [PATCH] Update csrf.go --- csrf.go | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/csrf.go b/csrf.go index 6b3fad8..381ca21 100644 --- a/csrf.go +++ b/csrf.go @@ -160,32 +160,28 @@ func Csrfer(opts ...Options) flamego.Handler { opt = opts[0] } - parseOptions := func(opts Options) Options { - if opt.Secret == "" { - opt.Secret = string(randomBytes(10)) - } + if opt.Secret == "" { + opt.Secret = string(randomBytes(10)) + } - if opt.Header == "" { - opt.Header = defaultHeader - } + if opt.Header == "" { + opt.Header = defaultHeader + } - if opt.Form == "" { - opt.Form = defaultForm - } + if opt.Form == "" { + opt.Form = defaultForm + } - if opt.SessionKey == "" { - opt.SessionKey = defaultSessionKey - } + if opt.SessionKey == "" { + opt.SessionKey = defaultSessionKey + } - if opt.ErrorFunc == nil { - opt.ErrorFunc = func(w http.ResponseWriter) { - http.Error(w, "Bad Request: invalid CSRF token", http.StatusBadRequest) - } + if opt.ErrorFunc == nil { + opt.ErrorFunc = func(w http.ResponseWriter) { + http.Error(w, "Bad Request: invalid CSRF token", http.StatusBadRequest) } - return opt } - opt = parseOptions(opt) return csrfInvoker(func(c flamego.Context, s session.Session) { x := &csrf{ secret: opt.Secret,