From 2a23f2fb9bca74302dcdc40def50c748da4a5e06 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Tue, 9 Jun 2020 16:20:31 +1000 Subject: Move serving 404 logic to domain package Simplify responsibilities of auth package and reduce complexity of app.go deciding which content to serve. --- internal/domain/domain.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'internal/domain/domain.go') 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) +} -- cgit v1.2.3