mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-04-24 22:06:57 +00:00
propagate ETag
This commit is contained in:
parent
cc32bab31f
commit
6dcb3b4ca0
2 changed files with 9 additions and 0 deletions
|
@ -25,6 +25,7 @@ type Client struct {
|
||||||
|
|
||||||
type FileResponse struct {
|
type FileResponse struct {
|
||||||
Exists bool
|
Exists bool
|
||||||
|
ETag []byte
|
||||||
MimeType string
|
MimeType string
|
||||||
Body []byte
|
Body []byte
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,6 +161,14 @@ func (o *Options) Upstream(ctx *fasthttp.RequestCtx, giteaClient *gitea.Client,
|
||||||
mimeType := o.getMimeTypeByExtension()
|
mimeType := o.getMimeTypeByExtension()
|
||||||
ctx.Response.Header.SetContentType(mimeType)
|
ctx.Response.Header.SetContentType(mimeType)
|
||||||
|
|
||||||
|
// Set ETag
|
||||||
|
if cachedResponse.Exists {
|
||||||
|
ctx.Response.Header.SetBytesV(fasthttp.HeaderETag, cachedResponse.ETag)
|
||||||
|
} else if res != nil {
|
||||||
|
cachedResponse.ETag = res.Header.Peek(fasthttp.HeaderETag)
|
||||||
|
ctx.Response.Header.SetBytesV(fasthttp.HeaderETag, cachedResponse.ETag)
|
||||||
|
}
|
||||||
|
|
||||||
if ctx.Response.StatusCode() != fasthttp.StatusNotFound {
|
if ctx.Response.StatusCode() != fasthttp.StatusNotFound {
|
||||||
// Everything's okay so far
|
// Everything's okay so far
|
||||||
ctx.Response.SetStatusCode(fasthttp.StatusOK)
|
ctx.Response.SetStatusCode(fasthttp.StatusOK)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue