mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-01-19 17:07:54 +00:00
first working
This commit is contained in:
parent
8a5a3cee5d
commit
dc023b81a8
2 changed files with 8 additions and 4 deletions
|
@ -28,6 +28,9 @@ func (c *Context) Context() stdContext.Context {
|
||||||
|
|
||||||
func (c *Context) Response() *http.Response {
|
func (c *Context) Response() *http.Response {
|
||||||
if c.Req != nil {
|
if c.Req != nil {
|
||||||
|
if c.Req.Response == nil {
|
||||||
|
c.Req.Response = &http.Response{Header: make(http.Header)}
|
||||||
|
}
|
||||||
return c.Req.Response
|
return c.Req.Response
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -17,9 +17,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
headerContentType = "Content-Type"
|
headerContentType = "Content-Type"
|
||||||
headerETag = "ETag"
|
headerETag = "ETag"
|
||||||
headerLastModified = "Last-Modified"
|
headerLastModified = "Last-Modified"
|
||||||
|
headerIfModifiedSince = "If-Modified-Since"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Upstream requests a file from the Gitea API at GiteaRoot and writes it to the request context.
|
// Upstream requests a file from the Gitea API at GiteaRoot and writes it to the request context.
|
||||||
|
@ -44,7 +45,7 @@ func (o *Options) Upstream(ctx *context.Context, giteaClient *gitea.Client) (fin
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the browser has a cached version
|
// Check if the browser has a cached version
|
||||||
if ifModifiedSince, err := time.Parse(time.RFC1123, string(ctx.Req.Response.Header.Get("If-Modified-Since"))); err == nil {
|
if ifModifiedSince, err := time.Parse(time.RFC1123, string(ctx.Response().Header.Get(headerIfModifiedSince))); err == nil {
|
||||||
if !ifModifiedSince.Before(o.BranchTimestamp) {
|
if !ifModifiedSince.Before(o.BranchTimestamp) {
|
||||||
ctx.RespWriter.WriteHeader(http.StatusNotModified)
|
ctx.RespWriter.WriteHeader(http.StatusNotModified)
|
||||||
return true
|
return true
|
||||||
|
|
Loading…
Reference in a new issue