diff --git a/server/context/context.go b/server/context/context.go index 02001fa..7aa4f01 100644 --- a/server/context/context.go +++ b/server/context/context.go @@ -28,6 +28,9 @@ func (c *Context) Context() stdContext.Context { func (c *Context) Response() *http.Response { if c.Req != nil { + if c.Req.Response == nil { + c.Req.Response = &http.Response{Header: make(http.Header)} + } return c.Req.Response } return nil diff --git a/server/upstream/upstream_std.go b/server/upstream/upstream_std.go index 72ca66c..ec62f7e 100644 --- a/server/upstream/upstream_std.go +++ b/server/upstream/upstream_std.go @@ -17,9 +17,10 @@ import ( ) const ( - headerContentType = "Content-Type" - headerETag = "ETag" - headerLastModified = "Last-Modified" + headerContentType = "Content-Type" + headerETag = "ETag" + headerLastModified = "Last-Modified" + headerIfModifiedSince = "If-Modified-Since" ) // 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 - 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) { ctx.RespWriter.WriteHeader(http.StatusNotModified) return true