set header as own func

This commit is contained in:
6543 2022-11-11 18:50:34 +01:00
parent 8c3b74518c
commit 9a44e26da7
No known key found for this signature in database
GPG key ID: B8BE6D610E61C862

View file

@ -172,21 +172,7 @@ func (o *Options) Upstream(ctx *context.Context, giteaClient *gitea.Client) (fin
} }
// Set ETag & MIME // Set ETag & MIME
if eTag := header.Get(gitea.ETagHeader); eTag != "" { setHeader(ctx, header, o.ServeRaw, o.BranchTimestamp)
ctx.RespWriter.Header().Set(gitea.ETagHeader, eTag)
}
if cacheIndicator := header.Get(gitea.PagesCacheIndicatorHeader); cacheIndicator != "" {
ctx.RespWriter.Header().Set(gitea.PagesCacheIndicatorHeader, cacheIndicator)
}
if length := header.Get(gitea.ContentLengthHeader); length != "" {
ctx.RespWriter.Header().Set(gitea.ContentLengthHeader, length)
}
if mime := header.Get(gitea.ContentTypeHeader); mime == "" || o.ServeRaw {
ctx.RespWriter.Header().Set(gitea.ContentTypeHeader, rawMime)
} else {
ctx.RespWriter.Header().Set(gitea.ContentTypeHeader, mime)
}
ctx.RespWriter.Header().Set(headerLastModified, o.BranchTimestamp.In(time.UTC).Format(time.RFC1123))
log.Debug().Msg("Prepare response") log.Debug().Msg("Prepare response")
@ -206,3 +192,22 @@ func (o *Options) Upstream(ctx *context.Context, giteaClient *gitea.Client) (fin
return true return true
} }
// setHeader set values to response header
func setHeader(ctx *context.Context, header http.Header, serveRaw bool, timestap time.Time) {
if eTag := header.Get(gitea.ETagHeader); eTag != "" {
ctx.RespWriter.Header().Set(gitea.ETagHeader, eTag)
}
if cacheIndicator := header.Get(gitea.PagesCacheIndicatorHeader); cacheIndicator != "" {
ctx.RespWriter.Header().Set(gitea.PagesCacheIndicatorHeader, cacheIndicator)
}
if length := header.Get(gitea.ContentLengthHeader); length != "" {
ctx.RespWriter.Header().Set(gitea.ContentLengthHeader, length)
}
if mime := header.Get(gitea.ContentTypeHeader); mime == "" || serveRaw {
ctx.RespWriter.Header().Set(gitea.ContentTypeHeader, rawMime)
} else {
ctx.RespWriter.Header().Set(gitea.ContentTypeHeader, mime)
}
ctx.RespWriter.Header().Set(headerLastModified, timestap.In(time.UTC).Format(time.RFC1123))
}