2023-06-19 14:42:47 -07:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2017-12-16 18:07:53 -08:00
|
|
|
|
2023-08-10 19:46:45 -07:00
|
|
|
package cookie // import "miniflux.app/v2/internal/http/cookie"
|
2017-12-16 18:07:53 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"time"
|
2024-04-30 01:21:23 +03:00
|
|
|
|
|
|
|
"miniflux.app/v2/internal/config"
|
2017-12-16 18:07:53 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
// Cookie names.
|
|
|
|
const (
|
2019-01-21 20:26:46 -08:00
|
|
|
CookieAppSessionID = "MinifluxAppSessionID"
|
|
|
|
CookieUserSessionID = "MinifluxUserSessionID"
|
2017-12-16 18:07:53 -08:00
|
|
|
)
|
|
|
|
|
2017-12-22 16:42:17 -08:00
|
|
|
// New creates a new cookie.
|
2018-02-03 15:33:17 -08:00
|
|
|
func New(name, value string, isHTTPS bool, path string) *http.Cookie {
|
2017-12-16 18:07:53 -08:00
|
|
|
return &http.Cookie{
|
|
|
|
Name: name,
|
|
|
|
Value: value,
|
2018-02-03 15:33:17 -08:00
|
|
|
Path: basePath(path),
|
2017-12-16 18:07:53 -08:00
|
|
|
Secure: isHTTPS,
|
|
|
|
HttpOnly: true,
|
2024-04-30 01:21:23 +03:00
|
|
|
Expires: time.Now().Add(time.Duration(config.Opts.CleanupRemoveSessionsDays()) * 24 * time.Hour),
|
2020-08-10 18:51:40 -07:00
|
|
|
SameSite: http.SameSiteLaxMode,
|
2017-12-16 18:07:53 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Expired returns an expired cookie.
|
2018-02-03 15:33:17 -08:00
|
|
|
func Expired(name string, isHTTPS bool, path string) *http.Cookie {
|
2017-12-16 18:07:53 -08:00
|
|
|
return &http.Cookie{
|
|
|
|
Name: name,
|
|
|
|
Value: "",
|
2018-02-03 15:33:17 -08:00
|
|
|
Path: basePath(path),
|
2017-12-16 18:07:53 -08:00
|
|
|
Secure: isHTTPS,
|
|
|
|
HttpOnly: true,
|
|
|
|
MaxAge: -1,
|
|
|
|
Expires: time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC),
|
2020-08-10 18:51:40 -07:00
|
|
|
SameSite: http.SameSiteLaxMode,
|
2017-12-16 18:07:53 -08:00
|
|
|
}
|
|
|
|
}
|
2018-02-03 15:33:17 -08:00
|
|
|
|
|
|
|
func basePath(path string) string {
|
|
|
|
if path == "" {
|
|
|
|
return "/"
|
|
|
|
}
|
|
|
|
return path
|
|
|
|
}
|