From 2533637ca527243c743458a573f80cc6dddd4644 Mon Sep 17 00:00:00 2001 From: Jaime Martinez Date: Tue, 13 Oct 2020 15:43:23 +1100 Subject: Cleanup a bit --- internal/domain/domain.go | 26 ++------------------------ internal/serving/disk/reader.go | 8 ++------ 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/internal/domain/domain.go b/internal/domain/domain.go index fe34d4d2..076dea0c 100644 --- a/internal/domain/domain.go +++ b/internal/domain/domain.go @@ -10,7 +10,6 @@ import ( "gitlab.com/gitlab-org/gitlab-pages/internal/httperrors" "gitlab.com/gitlab-org/gitlab-pages/internal/serving" - "gitlab.com/gitlab-org/gitlab-pages/internal/serving/disk/local" ) // Domain is a domain that gitlab-pages can serve. @@ -49,34 +48,13 @@ func (d *Domain) isSameProject(reqPath string) bool { func (d *Domain) resolve(r *http.Request) *serving.Request { if d.isSameProject(r.URL.Path) { - // // && strings. - // // Contains(r.URL. - // // Path, - // // d.servingRequest.LookupPath.Path) { - // fmt.Printf("d.resolve d: %q - count: %d\n - r.URL."+ - // "Path: %q - servingReq.Path: %q - servingReq."+ - // "SubPath: %q\n", - // d.Name, - // count[d.Name], - // r.URL.Path, - // d.servingRequest.LookupPath.Path, - // d.servingRequest.LookupPath.SubPath, - // ) return d.servingRequest } - request, _ := d.Resolver.Resolve(r) - - // TODO improve code around default serving, when `disk` serving gets removed - // https://gitlab.com/gitlab-org/gitlab-pages/issues/353 - if request == nil { - request = &serving.Request{Serving: local.Instance()} - } - // store serving.Request to avoid calling d.Resolver.Resolve multiple times - d.servingRequest = request + d.servingRequest, _ = d.Resolver.Resolve(r) - return request + return d.servingRequest } // GetLookupPath returns a project details based on the request. It returns nil diff --git a/internal/serving/disk/reader.go b/internal/serving/disk/reader.go index 28ca1114..34f2c5fc 100644 --- a/internal/serving/disk/reader.go +++ b/internal/serving/disk/reader.go @@ -61,12 +61,8 @@ func (reader *Reader) tryFile(w http.ResponseWriter, r *http.Request, lookupPath return err } - fullPath, err := reader.resolvePath(ctx, root, lookupPath.SubPath) - - // request := h.Request - host := r.Host urlPath := r.URL.Path - + fullPath, err := reader.resolvePath(ctx, root, lookupPath.SubPath) if locationError, _ := err.(*locationDirectoryError); locationError != nil { if endsWithSlash(urlPath) { fullPath, err = reader.resolvePath(ctx, root, lookupPath.SubPath, @@ -76,7 +72,7 @@ func (reader *Reader) tryFile(w http.ResponseWriter, r *http.Request, lookupPath // issue about this: https://gitlab.com/gitlab-org/gitlab-pages/issues/273 // Concat Host with URL.Path - redirectPath := "//" + host + "/" + redirectPath := "//" + r.Host + "/" redirectPath += strings.TrimPrefix(urlPath, "/") // Ensure that there's always "/" at end -- cgit v1.2.3