diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2020-06-09 09:20:31 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2020-07-06 02:13:51 +0300 |
commit | 2a23f2fb9bca74302dcdc40def50c748da4a5e06 (patch) | |
tree | 31698c64ca1b9b8dc370aa42d5015c63f5ca7fcb /internal/domain/domain.go | |
parent | 8e4dff76f1015bf10bdaedc295f726e80958bba1 (diff) |
Move serving 404 logic to domain package
Simplify responsibilities of auth package and reduce
complexity of app.go deciding which content to serve.
Diffstat (limited to 'internal/domain/domain.go')
-rw-r--r-- | internal/domain/domain.go | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/internal/domain/domain.go b/internal/domain/domain.go index 2a301121..9fa843a3 100644 --- a/internal/domain/domain.go +++ b/internal/domain/domain.go @@ -169,14 +169,14 @@ func (d *Domain) ServeNotFoundHTTP(w http.ResponseWriter, r *http.Request) { request.ServeNotFoundHTTP(w, r) } -// ServeNamespaceNotFound will try to find a parent namespace domain for a request +// serveNamespaceNotFound will try to find a parent namespace domain for a request // that failed authentication so that we serve the custom namespace error page for // public namespace domains -func (d *Domain) ServeNamespaceNotFound(w http.ResponseWriter, r *http.Request) { - // override the path nd try to resolve the domain name +func (d *Domain) serveNamespaceNotFound(w http.ResponseWriter, r *http.Request) { + // override the path and try to resolve the domain name r.URL.Path = "/" namespaceDomain, err := d.Resolver.Resolve(r) - if err != nil { + if err != nil || namespaceDomain.LookupPath == nil { httperrors.Serve404(w) return } @@ -189,3 +189,18 @@ func (d *Domain) ServeNamespaceNotFound(w http.ResponseWriter, r *http.Request) httperrors.Serve404(w) } + +// ServeNotFoundAuthFailed handler to be called when auth failed so the correct custom +// 404 page is served. +func (d *Domain) ServeNotFoundAuthFailed(w http.ResponseWriter, r *http.Request) { + if d.isUnconfigured() || !d.HasLookupPath(r) { + httperrors.Serve404(w) + return + } + if d.IsNamespaceProject(r) { + d.ServeNotFoundHTTP(w, r) + return + } + + d.serveNamespaceNotFound(w, r) +} |