From 9c4299720900fce52daedfce2314d31e92f7fe1d Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sat, 3 Feb 2018 15:33:17 -0800 Subject: Add support for base URLs with subfolders --- http/cookie/cookie.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'http/cookie') 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 +} -- cgit v1.2.3