parse url correctly?
This commit is contained in:
parent
54946a45d7
commit
1955acce05
|
@ -19,10 +19,11 @@ const giteaAPIRepos = "/api/v1/repos/"
|
|||
|
||||
func giteaRawContent(targetOwner, targetRepo, ref, giteaRoot, giteaAPIToken, resource string) ([]byte, error) {
|
||||
req := fasthttp.AcquireRequest()
|
||||
baseUrl, _ := url.Parse(giteaRoot)
|
||||
apiPath, _ := baseUrl.Parse(path.Join(giteaAPIRepos, targetOwner, targetRepo, "raw", resource+"?ref="+url.QueryEscape(ref)))
|
||||
|
||||
apiPath := path.Join(giteaRoot, giteaAPIRepos, targetOwner, targetRepo, "raw", resource+"?ref="+url.QueryEscape(ref))
|
||||
log.Debug().Msgf("giteaRawContent: trying path %s", apiPath)
|
||||
req.SetRequestURI(apiPath)
|
||||
req.SetRequestURI(apiPath.String())
|
||||
req.Header.Set(fasthttp.HeaderAuthorization, giteaAPIToken)
|
||||
res := fasthttp.AcquireResponse()
|
||||
|
||||
|
@ -39,14 +40,16 @@ func giteaGetRepoBranchTimestamp(giteaRoot, repoOwner, repoName, branchName, git
|
|||
client := getFastHTTPClient(5 * time.Second)
|
||||
|
||||
req := fasthttp.AcquireRequest()
|
||||
apiPath := path.Join(giteaRoot, giteaAPIRepos, repoOwner, repoName, "branches", branchName)
|
||||
baseUrl, _ := url.Parse(giteaRoot)
|
||||
apiPath, _ := baseUrl.Parse(path.Join(giteaAPIRepos, repoOwner, repoName, "branches", branchName))
|
||||
|
||||
log.Debug().Msgf("giteaGetRepoBranchTimestamp: trying path %s", apiPath)
|
||||
req.SetRequestURI(apiPath)
|
||||
req.SetRequestURI(apiPath.String())
|
||||
req.Header.Set(fasthttp.HeaderAuthorization, giteaAPIToken)
|
||||
res := fasthttp.AcquireResponse()
|
||||
|
||||
if err := client.Do(req, res); err != nil {
|
||||
log.Err(err)
|
||||
log.Err(err).Msg("giteaGetRepoBranchTimestamp: failed api lookup")
|
||||
return time.Time{}, err
|
||||
}
|
||||
if res.StatusCode() != fasthttp.StatusOK {
|
||||
|
@ -60,14 +63,16 @@ func giteaGetRepoDefaultBranch(giteaRoot, repoOwner, repoName, giteaAPIToken str
|
|||
client := getFastHTTPClient(5 * time.Second)
|
||||
|
||||
req := fasthttp.AcquireRequest()
|
||||
apiPath := path.Join(giteaRoot, giteaAPIRepos, repoOwner, repoName)
|
||||
log.Debug().Msgf("trying path %s", apiPath)
|
||||
req.SetRequestURI(apiPath)
|
||||
baseUrl, _ := url.Parse(giteaRoot)
|
||||
apiPath, _ := baseUrl.Parse(path.Join(giteaRoot, giteaAPIRepos, repoOwner, repoName))
|
||||
|
||||
log.Debug().Msgf("giteaGetRepoDefaultBranch: trying path %s", apiPath)
|
||||
req.SetRequestURI(apiPath.String())
|
||||
req.Header.Set(fasthttp.HeaderAuthorization, giteaAPIToken)
|
||||
res := fasthttp.AcquireResponse()
|
||||
|
||||
if err := client.Do(req, res); err != nil {
|
||||
log.Err(err)
|
||||
log.Err(err).Msg("giteaGetRepoDefaultBranch: failed api lookup")
|
||||
return "", err
|
||||
}
|
||||
if res.StatusCode() != fasthttp.StatusOK {
|
||||
|
|
|
@ -30,7 +30,7 @@ func GetBranchTimestamp(owner, repo, branch, giteaRoot, giteaAPIToken string, br
|
|||
// Get default branch
|
||||
defaultBranch, err := giteaGetRepoDefaultBranch(giteaRoot, owner, repo, giteaAPIToken)
|
||||
if err != nil {
|
||||
log.Err(err)
|
||||
log.Err(err).Msg("GetBranchTimestamp: something went wrong with giteaGetRepoDefaultBranch")
|
||||
_ = branchTimestampCache.Set(owner+"/"+repo+"/", nil, defaultBranchCacheTimeout)
|
||||
return nil
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ func GetBranchTimestamp(owner, repo, branch, giteaRoot, giteaAPIToken string, br
|
|||
|
||||
timestamp, err := giteaGetRepoBranchTimestamp(giteaRoot, owner, repo, branch, giteaAPIToken)
|
||||
if err != nil {
|
||||
log.Err(err)
|
||||
log.Err(err).Msg("GetBranchTimestamp: something went wrong with giteaGetRepoBranchTimestamp")
|
||||
return nil
|
||||
}
|
||||
result.Timestamp = timestamp
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"mime"
|
||||
"net/url"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -93,7 +94,9 @@ func (o *Options) Upstream(ctx *fasthttp.RequestCtx, giteaRoot, giteaAPIToken st
|
|||
cachedResponse = cachedValue.(fileResponse)
|
||||
} else {
|
||||
req = fasthttp.AcquireRequest()
|
||||
req.SetRequestURI(path.Join(giteaRoot, giteaAPIRepos, uri))
|
||||
baseUrl, _ := url.Parse(giteaRoot)
|
||||
apiPath, _ := baseUrl.Parse(path.Join(giteaAPIRepos, uri))
|
||||
req.SetRequestURI(apiPath.String())
|
||||
req.Header.Set(fasthttp.HeaderAuthorization, giteaAPIToken)
|
||||
res = fasthttp.AcquireResponse()
|
||||
res.SetBodyStream(&strings.Reader{}, -1)
|
||||
|
|
Loading…
Reference in New Issue