fix panic when upstream fails (#412)

Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/412
Co-authored-by: crapStone <me@crapstone.dev>
Co-committed-by: crapStone <me@crapstone.dev>
This commit is contained in:
crapStone 2024-12-29 15:43:30 +00:00 committed by crapStone
parent e079ce4cf4
commit 2438de0eb2
2 changed files with 6 additions and 3 deletions

View file

@ -20,8 +20,8 @@
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 0, "lastModified": 0,
"narHash": "sha256-29QfSvJwpjNwppFnU33nnyedAWpaaDBSlDJZzJhg97s=", "narHash": "sha256-UA56kDQSztRWbpsG9bK+jIGyZ0YZAcIsYAhXDHIr8zs=",
"path": "/nix/store/1703v0vkmk136sca5rf1861jrn2ndajr-source", "path": "/nix/store/np3i3qi6hq6d1p5xr36cjmr0xwd2j289-source",
"type": "path" "type": "path"
}, },
"original": { "original": {

View file

@ -183,9 +183,12 @@ func (o *Options) Upstream(ctx *context.Context, giteaClient *gitea.Client, redi
// add extension for encoding // add extension for encoding
path := o.TargetPath + allowedEncodings[encoding] path := o.TargetPath + allowedEncodings[encoding]
reader, header, statusCode, err = giteaClient.ServeRawContent(o.TargetOwner, o.TargetRepo, o.TargetBranch, path, true) reader, header, statusCode, err = giteaClient.ServeRawContent(o.TargetOwner, o.TargetRepo, o.TargetBranch, path, true)
if statusCode == 404 { if statusCode == http.StatusNotFound {
continue continue
} }
if err != nil {
break
}
log.Debug().Msgf("using %s encoding", encoding) log.Debug().Msgf("using %s encoding", encoding)
if encoding != "identity" { if encoding != "identity" {
header.Set(headerContentEncoding, encoding) header.Set(headerContentEncoding, encoding)