From 2438de0eb2d843a99d7e2a0fb6a71db8c9c70e2e Mon Sep 17 00:00:00 2001 From: crapStone Date: Sun, 29 Dec 2024 15:43:30 +0000 Subject: [PATCH] fix panic when upstream fails (#412) Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/412 Co-authored-by: crapStone Co-committed-by: crapStone --- flake.lock | 4 ++-- server/upstream/upstream.go | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index 5eb7802..1062fa4 100644 --- a/flake.lock +++ b/flake.lock @@ -20,8 +20,8 @@ "nixpkgs": { "locked": { "lastModified": 0, - "narHash": "sha256-29QfSvJwpjNwppFnU33nnyedAWpaaDBSlDJZzJhg97s=", - "path": "/nix/store/1703v0vkmk136sca5rf1861jrn2ndajr-source", + "narHash": "sha256-UA56kDQSztRWbpsG9bK+jIGyZ0YZAcIsYAhXDHIr8zs=", + "path": "/nix/store/np3i3qi6hq6d1p5xr36cjmr0xwd2j289-source", "type": "path" }, "original": { diff --git a/server/upstream/upstream.go b/server/upstream/upstream.go index 98137ba..2abd0b9 100644 --- a/server/upstream/upstream.go +++ b/server/upstream/upstream.go @@ -183,9 +183,12 @@ func (o *Options) Upstream(ctx *context.Context, giteaClient *gitea.Client, redi // add extension for encoding path := o.TargetPath + allowedEncodings[encoding] reader, header, statusCode, err = giteaClient.ServeRawContent(o.TargetOwner, o.TargetRepo, o.TargetBranch, path, true) - if statusCode == 404 { + if statusCode == http.StatusNotFound { continue } + if err != nil { + break + } log.Debug().Msgf("using %s encoding", encoding) if encoding != "identity" { header.Set(headerContentEncoding, encoding)