mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2024-11-18 10:29:43 +00:00
Do not cache incomplete requests
This commit is contained in:
parent
18d09a163c
commit
f6ed4285bc
1 changed files with 5 additions and 1 deletions
|
@ -100,11 +100,15 @@ type writeCacheReader struct {
|
||||||
cache cache.ICache
|
cache cache.ICache
|
||||||
hasError bool
|
hasError bool
|
||||||
doNotCache bool
|
doNotCache bool
|
||||||
|
complete bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *writeCacheReader) Read(p []byte) (n int, err error) {
|
func (t *writeCacheReader) Read(p []byte) (n int, err error) {
|
||||||
log.Trace().Msgf("[cache] read %q", t.cacheKey)
|
log.Trace().Msgf("[cache] read %q", t.cacheKey)
|
||||||
n, err = t.originalReader.Read(p)
|
n, err = t.originalReader.Read(p)
|
||||||
|
if err == io.EOF {
|
||||||
|
t.complete = true
|
||||||
|
}
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
log.Trace().Err(err).Msgf("[cache] original reader for %q has returned an error", t.cacheKey)
|
log.Trace().Err(err).Msgf("[cache] original reader for %q has returned an error", t.cacheKey)
|
||||||
t.hasError = true
|
t.hasError = true
|
||||||
|
@ -120,7 +124,7 @@ func (t *writeCacheReader) Read(p []byte) (n int, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *writeCacheReader) Close() error {
|
func (t *writeCacheReader) Close() error {
|
||||||
doWrite := !t.hasError && !t.doNotCache
|
doWrite := !t.hasError && !t.doNotCache && t.complete
|
||||||
fc := *t.fileResponse
|
fc := *t.fileResponse
|
||||||
fc.Body = t.buffer.Bytes()
|
fc.Body = t.buffer.Bytes()
|
||||||
if doWrite {
|
if doWrite {
|
||||||
|
|
Loading…
Reference in a new issue