mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-25 06:16:58 +00:00
magic
This commit is contained in:
parent
4a2a14272b
commit
94cb43508c
2 changed files with 57 additions and 30 deletions
|
@ -158,26 +158,12 @@ func (client *Client) ServeRawContent(targetOwner, targetRepo, ref, resource str
|
|||
}
|
||||
|
||||
// now we write to cache and respond at the sime time
|
||||
|
||||
// TODO: at the sime time !!!
|
||||
/*
|
||||
we create a new type that implement an writer witch write to cache based on key etc ...
|
||||
// TODO: cache is half-empty if request is cancelled - does the ctx.Err() below do the trick?
|
||||
// err = res.BodyWriteTo(io.MultiWriter(ctx.Response().BodyWriter(), &cacheBodyWriter))
|
||||
*/
|
||||
body, err := io.ReadAll(io.LimitReader(reader, fileCacheSizeLimit))
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("not expected")
|
||||
}
|
||||
if err := client.responseCache.Set(cacheKey, FileResponse{
|
||||
fileResp := FileResponse{
|
||||
Exists: true,
|
||||
ETag: resp.Header.Get(eTagHeader),
|
||||
MimeType: mimeType,
|
||||
Body: body,
|
||||
}, fileCacheTimeout); err != nil {
|
||||
log.Error().Err(err).Msg("could not save content in cache")
|
||||
}
|
||||
return io.NopCloser(bytes.NewReader(body)), resp.Response, nil
|
||||
return fileResp.CreateCacheReader(reader, client.responseCache, cacheKey), resp.Response, nil
|
||||
}
|
||||
|
||||
case http.StatusNotFound:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue