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

View file

@ -418,7 +418,7 @@ func upstream(ctx *fasthttp.RequestCtx, targetOwner string, targetRepo string, t
var res *fasthttp.Response var res *fasthttp.Response
var cachedResponse fileResponse var cachedResponse fileResponse
var err error 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) cachedResponse = cachedValue.(fileResponse)
} else { } else {
req = fasthttp.AcquireRequest() req = fasthttp.AcquireRequest()
@ -504,7 +504,7 @@ func upstream(ctx *fasthttp.RequestCtx, targetOwner string, targetRepo string, t
} }
s.Step("response") s.Step("response")
if res != nil { if res != nil && ctx.Err() == nil {
cachedResponse.exists = true cachedResponse.exists = true
cachedResponse.mimeType = mimeType cachedResponse.mimeType = mimeType
cachedResponse.body = cacheBodyWriter.Bytes() cachedResponse.body = cacheBodyWriter.Bytes()