diff options
Diffstat (limited to 'internal/auth/session.go')
-rw-r--r-- | internal/auth/session.go | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/internal/auth/session.go b/internal/auth/session.go index c9b4ee8d..c0a3d370 100644 --- a/internal/auth/session.go +++ b/internal/auth/session.go @@ -2,21 +2,26 @@ package auth import ( "net/http" + "strings" "github.com/gorilla/sessions" "gitlab.com/gitlab-org/labkit/log" "gitlab.com/gitlab-org/gitlab-pages/internal/errortracking" + "gitlab.com/gitlab-org/gitlab-pages/internal/feature" "gitlab.com/gitlab-org/gitlab-pages/internal/httperrors" "gitlab.com/gitlab-org/gitlab-pages/internal/request" ) +const ( + sessionHostKey = "_session_host" + namespaceInPathKey = "_namespace_in_path" +) + type hostSession struct { *sessions.Session } -const sessionHostKey = "_session_host" - func (s *hostSession) Save(r *http.Request, w http.ResponseWriter) error { s.Session.Values[sessionHostKey] = r.Host @@ -24,11 +29,16 @@ func (s *hostSession) Save(r *http.Request, w http.ResponseWriter) error { } func (s *hostSession) getNamespaceInPathFromSession() string { - namespaceInPath := "" - if len(s.Options.Path) > 1 && s.Options.Path[0] == '/' { - namespaceInPath = s.Options.Path[1:] + if s.Values[namespaceInPathKey] != nil { + return s.Values[namespaceInPathKey].(string) + } + return "" +} + +func (s *hostSession) appendPath(path string) { + if feature.ProjectPrefixCookiePath.Enabled() && len(path) > 0 { + s.Options.Path = strings.TrimSuffix(s.Options.Path, "/") + "/" + strings.Trim(path, "/") } - return namespaceInPath } func (a *Auth) getSessionFromStore(r *http.Request) (*hostSession, error) { @@ -52,6 +62,9 @@ func (a *Auth) getSessionFromStore(r *http.Request) (*hostSession, error) { session.Values = make(map[interface{}]interface{}) } + if len(namespaceInPath) > 0 { + session.Values[namespaceInPathKey] = namespaceInPathKey + } } return &hostSession{session}, err |