From d84955e6cd0a9149430d284e07c178d222a65590 Mon Sep 17 00:00:00 2001 From: ~lucidiot Date: Wed, 20 Jul 2022 16:21:35 +0000 Subject: [PATCH] Fix URL building for default repo branch API Using the base URL in path.Join caused it to remove the two slashes (because /////tmp == /tmp): `https:/tildegit.org/api/v1/repos/owner/name` Then, using that in URL.Parse causes it to see a `https:` scheme, and the / right afterwards means "start a path here", not a hostname, because hostnames begin with two slashes. That's a valid URL, with no hostname. Then it gets turned back into a string: `https:///tildegit.org/api/v1/repos/owner/name` That's another way of expressing the same URL with no hostname: ///. curl, Firefox and Chromium all fix the triple slash automatically, but fasthttp doesn't, and it tries to look up the empty string as a DNS host! --- server/upstream/gitea.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/upstream/gitea.go b/server/upstream/gitea.go index ed97071..75fe4a8 100644 --- a/server/upstream/gitea.go +++ b/server/upstream/gitea.go @@ -64,7 +64,7 @@ func giteaGetRepoDefaultBranch(giteaRoot, repoOwner, repoName, giteaAPIToken str req := fasthttp.AcquireRequest() baseUrl, _ := url.Parse(giteaRoot) - apiPath, _ := baseUrl.Parse(path.Join(giteaRoot, giteaAPIRepos, repoOwner, repoName)) + apiPath, _ := baseUrl.Parse(path.Join(giteaAPIRepos, repoOwner, repoName)) log.Debug().Msgf("giteaGetRepoDefaultBranch: trying path %s", apiPath) req.SetRequestURI(apiPath.String())