Merge pull request 'Fix (half) empty cache issue' (#17) from bugfix/large-files-are-empty into main

Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/17
This commit is contained in:
Moritz Marquardt 2021-12-02 20:35:22 +01:00
commit 726d8321e8
1 changed files with 2 additions and 2 deletions

View File

@ -418,7 +418,7 @@ func upstream(ctx *fasthttp.RequestCtx, targetOwner string, targetRepo string, t
var res *fasthttp.Response
var cachedResponse fileResponse
var err error
if cachedValue, ok := fileResponseCache.Get(uri + "?timestamp=" + strconv.FormatInt(options.BranchTimestamp.Unix(), 10)); ok {
if cachedValue, ok := fileResponseCache.Get(uri + "?timestamp=" + strconv.FormatInt(options.BranchTimestamp.Unix(), 10)); ok && len(cachedValue.(fileResponse).body) > 0 {
cachedResponse = cachedValue.(fileResponse)
} else {
req = fasthttp.AcquireRequest()
@ -504,7 +504,7 @@ func upstream(ctx *fasthttp.RequestCtx, targetOwner string, targetRepo string, t
}
s.Step("response")
if res != nil {
if res != nil && ctx.Err() == nil {
cachedResponse.exists = true
cachedResponse.mimeType = mimeType
cachedResponse.body = cacheBodyWriter.Bytes()