From cf56c1ccf0cf40f711bd91c222a275778558e0e9 Mon Sep 17 00:00:00 2001 From: Patrick Peng Sun Date: Sun, 16 Jul 2017 23:14:36 +1000 Subject: [PATCH] clear cookie --- crmpixel.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/crmpixel.go b/crmpixel.go index c437f22..d28b2e8 100644 --- a/crmpixel.go +++ b/crmpixel.go @@ -106,6 +106,13 @@ func cookieCreate(name, value string, expireInSeconds int) (ret http.Cookie) { return } +//set to "" and make it expire +func cookieClear(name string) (ret http.Cookie) { + expiration := time.Unix(0, 0) //Epoc + ret = http.Cookie{Name: name, Value: "", Expires: expiration} + return +} + func crmCreateNewAnonymousLeadByHTTPRequest(r *http.Request) (info crmdLead) { info.FirstName = "Anonymous" info.LastName = "User " + r.RemoteAddr @@ -230,6 +237,7 @@ func setTrackingCookieAndRecirect(w http.ResponseWriter, r *http.Request) { if ok { log.Println("setlead cookie :" + leadID[0]) cookie := cookieFromLeadID(leadID[0]) + log.Println(cookie) http.SetCookie(w, &cookie) } else { cookie := crmpixelCookie(r) @@ -248,9 +256,16 @@ func setTrackingCookieAndRecirect(w http.ResponseWriter, r *http.Request) { if k == "lid" || k == "url" || k == "expire" || k == "nonce" || k == "signature" || k == "timestamp" { //skip lead id and URL and expire continue } - log.Printf("set cookie %s=%s", k, v) - cookie := cookieCreate(k, v[0], expire) - http.SetCookie(w, &cookie) + + if v[0] != "" { + log.Printf("set cookie %s=%s", k, v) + cookie := cookieCreate(k, v[0], expire) + http.SetCookie(w, &cookie) + } else { //clear cook + log.Printf("clear cookie %s=%s", k, v) + cookie := cookieClear(k) + http.SetCookie(w, &cookie) + } } //perform redirect