From f6ed4285bced36000b9fae1a29bd028b75200daa Mon Sep 17 00:00:00 2001 From: Moritz Marquardt Date: Tue, 16 Apr 2024 22:38:48 +0200 Subject: [PATCH] Do not cache incomplete requests --- server/gitea/cache.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/gitea/cache.go b/server/gitea/cache.go index 8a2b06a..15504b7 100644 --- a/server/gitea/cache.go +++ b/server/gitea/cache.go @@ -100,11 +100,15 @@ type writeCacheReader struct { cache cache.ICache hasError bool doNotCache bool + complete bool } func (t *writeCacheReader) Read(p []byte) (n int, err error) { log.Trace().Msgf("[cache] read %q", t.cacheKey) n, err = t.originalReader.Read(p) + if err == io.EOF { + t.complete = true + } if err != nil && err != io.EOF { log.Trace().Err(err).Msgf("[cache] original reader for %q has returned an error", t.cacheKey) t.hasError = true @@ -120,7 +124,7 @@ func (t *writeCacheReader) Read(p []byte) (n int, err error) { } func (t *writeCacheReader) Close() error { - doWrite := !t.hasError && !t.doNotCache + doWrite := !t.hasError && !t.doNotCache && t.complete fc := *t.fileResponse fc.Body = t.buffer.Bytes() if doWrite {