diff options
author | Kassio Borges <kassioborgesm@gmail.com> | 2024-01-22 17:53:08 +0300 |
---|---|---|
committer | Kassio Borges <kassioborgesm@gmail.com> | 2024-01-22 17:55:06 +0300 |
commit | 92ac92eb9b87fed87760fc4862dbbed112e8ee60 (patch) | |
tree | 2ad2e1c07fa1316715079c90b28cae4e0c51d57e | |
parent | 355a2950d0e40e2ccb106fea99fb00c03280c1ae (diff) |
Do not change the request capitalization
-rw-r--r-- | internal/source/gitlab/client/testdata/test.gitlab.io.json | 11 | ||||
-rw-r--r-- | internal/source/gitlab/gitlab.go | 9 | ||||
-rw-r--r-- | internal/source/gitlab/gitlab_test.go | 20 |
3 files changed, 29 insertions, 11 deletions
diff --git a/internal/source/gitlab/client/testdata/test.gitlab.io.json b/internal/source/gitlab/client/testdata/test.gitlab.io.json index c094e52a..086123a9 100644 --- a/internal/source/gitlab/client/testdata/test.gitlab.io.json +++ b/internal/source/gitlab/client/testdata/test.gitlab.io.json @@ -34,6 +34,17 @@ "type": "file", "sha256": "0f8ef3377b30fc47f96b48247f463a726a802f62f3faa03d56403751d2f66c67" } + }, + { + "access_control": false, + "https_only": true, + "prefix": "/my/capitalizedprefix/", + "project_id": 126, + "source": { + "path": "some/path/to/project/", + "type": "file", + "sha256": "a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3" + } } ] } diff --git a/internal/source/gitlab/gitlab.go b/internal/source/gitlab/gitlab.go index 2de113f8..fe175aaf 100644 --- a/internal/source/gitlab/gitlab.go +++ b/internal/source/gitlab/gitlab.go @@ -72,18 +72,19 @@ func (g *Gitlab) Resolve(r *http.Request) (*serving.Request, error) { return nil, response.Error } - urlPath := strings.ToLower(path.Clean(r.URL.Path)) + urlPath := path.Clean(r.URL.Path) + lowerUrlPath := strings.ToLower(urlPath) size := len(response.Domain.LookupPaths) for _, lookup := range response.Domain.LookupPaths { lookupPrefix := strings.ToLower(lookup.Prefix) - isSubPath := strings.HasPrefix(urlPath, lookupPrefix) - isRootPath := urlPath == path.Clean(lookupPrefix) + isSubPath := strings.HasPrefix(lowerUrlPath, lookupPrefix) + isRootPath := lowerUrlPath == path.Clean(lookupPrefix) if isSubPath || isRootPath { subPath := "" if isSubPath { - subPath = strings.TrimPrefix(urlPath, lookupPrefix) + subPath = urlPath[len(lookupPrefix):] } srv, err := g.fabricateServing(lookup) diff --git a/internal/source/gitlab/gitlab_test.go b/internal/source/gitlab/gitlab_test.go index d99e88e9..6d5d978a 100644 --- a/internal/source/gitlab/gitlab_test.go +++ b/internal/source/gitlab/gitlab_test.go @@ -116,13 +116,19 @@ func TestResolve(t *testing.T) { expectedPath: "some/path/to/project/", expectedSubPath: "index.html", }, - "when request path is capitalized": { - file: "client/testdata/test.gitlab.io.json", - target: "https://test.gitlab.io:443/My/Pages/Project/path/index.html", - expectedPrefix: "/my/pages/project/", - expectedPath: "some/path/to/project/", - expectedSubPath: "path/index.html", - expectedIsNamespace: false, + "when project name requested is capitalized": { + file: "client/testdata/test.gitlab.io.json", + target: "https://test.gitlab.io:443/My/CapitalizedPrefix", + expectedPrefix: "/my/capitalizedprefix/", + expectedPath: "some/path/to/project/", + expectedSubPath: "", + }, + "when project name and requested path are capitalized": { + file: "client/testdata/test.gitlab.io.json", + target: "https://test.gitlab.io:443/My/CapitalizedPrefix/Path/Index.html", + expectedPrefix: "/my/capitalizedprefix/", + expectedPath: "some/path/to/project/", + expectedSubPath: "Path/Index.html", }, } |