mirror of
https://github.com/drakkan/sftpgo.git
synced 2024-11-22 07:30:25 +00:00
66945c0a02
Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
46 lines
950 B
Go
46 lines
950 B
Go
package httpd
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
flashCookieName = "message"
|
|
)
|
|
|
|
func setFlashMessage(w http.ResponseWriter, r *http.Request, value string) {
|
|
http.SetCookie(w, &http.Cookie{
|
|
Name: flashCookieName,
|
|
Value: base64.URLEncoding.EncodeToString([]byte(value)),
|
|
Path: "/",
|
|
Expires: time.Now().Add(60 * time.Second),
|
|
MaxAge: 60,
|
|
HttpOnly: true,
|
|
Secure: isTLS(r),
|
|
SameSite: http.SameSiteLaxMode,
|
|
})
|
|
}
|
|
|
|
func getFlashMessage(w http.ResponseWriter, r *http.Request) string {
|
|
cookie, err := r.Cookie(flashCookieName)
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
http.SetCookie(w, &http.Cookie{
|
|
Name: flashCookieName,
|
|
Value: "",
|
|
Path: "/",
|
|
Expires: time.Unix(0, 0),
|
|
MaxAge: -1,
|
|
HttpOnly: true,
|
|
Secure: isTLS(r),
|
|
SameSite: http.SameSiteLaxMode,
|
|
})
|
|
message, err := base64.URLEncoding.DecodeString(cookie.Value)
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
return string(message)
|
|
}
|