From bcaceda71177d701f91c01eb04213e126de71ea0 Mon Sep 17 00:00:00 2001 From: 6543 <6543@noreply.codeberg.org> Date: Fri, 15 Jul 2022 21:21:26 +0200 Subject: [PATCH] dont cache if ContentLength greater fileCacheSizeLimit (#108) Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/108 Reviewed-by: Otto --- Justfile | 4 ++++ server/upstream/upstream.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Justfile b/Justfile index a908e7a..c824efa 100644 --- a/Justfile +++ b/Justfile @@ -21,6 +21,10 @@ lint: tool-golangci tool-gofumpt fmt: tool-gofumpt gofumpt -w --extra . +clean: + go clean ./... + rm -rf build/ + tool-golangci: @hash golangci-lint> /dev/null 2>&1; if [ $? -ne 0 ]; then \ go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \ diff --git a/server/upstream/upstream.go b/server/upstream/upstream.go index b9fc2bc..5e888ac 100644 --- a/server/upstream/upstream.go +++ b/server/upstream/upstream.go @@ -199,7 +199,7 @@ func (o *Options) Upstream(ctx *fasthttp.RequestCtx, giteaClient *gitea.Client, } log.Debug().Msg("response") - if res != nil && ctx.Err() == nil { + if res != nil && res.Header.ContentLength() > fileCacheSizeLimit && ctx.Err() == nil { cachedResponse.Exists = true cachedResponse.MimeType = mimeType cachedResponse.Body = cacheBodyWriter.Bytes()