aboutsummaryrefslogtreecommitdiffhomepage
path: root/http
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <fred@miniflux.net>2018-02-03 15:33:17 -0800
committerGravatar Frédéric Guillot <fred@miniflux.net>2018-02-03 15:33:17 -0800
commit9c4299720900fce52daedfce2314d31e92f7fe1d (patch)
tree2a67a75d71011d071910a4cb4216d45ee9d904c4 /http
parent78385a351e208feb183549c2fa854b302da0c690 (diff)
Add support for base URLs with subfolders
Diffstat (limited to 'http')
-rw-r--r--http/cookie/cookie.go15
-rw-r--r--http/middleware/session.go2
2 files changed, 12 insertions, 5 deletions
diff --git a/http/cookie/cookie.go b/http/cookie/cookie.go
index d1f3e72..4407daa 100644
--- a/http/cookie/cookie.go
+++ b/http/cookie/cookie.go
@@ -19,11 +19,11 @@ const (
)
// New creates a new cookie.
-func New(name, value string, isHTTPS bool) *http.Cookie {
+func New(name, value string, isHTTPS bool, path string) *http.Cookie {
return &http.Cookie{
Name: name,
Value: value,
- Path: "/",
+ Path: basePath(path),
Secure: isHTTPS,
HttpOnly: true,
Expires: time.Now().Add(cookieDuration * 24 * time.Hour),
@@ -31,14 +31,21 @@ func New(name, value string, isHTTPS bool) *http.Cookie {
}
// Expired returns an expired cookie.
-func Expired(name string, isHTTPS bool) *http.Cookie {
+func Expired(name string, isHTTPS bool, path string) *http.Cookie {
return &http.Cookie{
Name: name,
Value: "",
- Path: "/",
+ Path: basePath(path),
Secure: isHTTPS,
HttpOnly: true,
MaxAge: -1,
Expires: time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC),
}
}
+
+func basePath(path string) string {
+ if path == "" {
+ return "/"
+ }
+ return path
+}
diff --git a/http/middleware/session.go b/http/middleware/session.go
index c3876f6..9b7dd86 100644
--- a/http/middleware/session.go
+++ b/http/middleware/session.go
@@ -36,7 +36,7 @@ func (s *SessionMiddleware) Handler(next http.Handler) http.Handler {
return
}
- http.SetCookie(w, cookie.New(cookie.CookieSessionID, session.ID, s.cfg.IsHTTPS))
+ http.SetCookie(w, cookie.New(cookie.CookieSessionID, session.ID, s.cfg.IsHTTPS, s.cfg.BasePath()))
} else {
logger.Debug("[Middleware:Session] %s", session)
}