diff options
author | KN4CK3R <admin@oldschoolhack.me> | 2022-11-24 15:25:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-24 16:25:13 +0200 |
commit | fc7a2d5a959334f7195571a3e1db669ed7667a28 (patch) | |
tree | e03df232ebc29e508680686c396cfecb4eeb0902 /modules | |
parent | 26f941fbdac73844a93c902ce6d1144175ff23ed (diff) | |
download | gitea-fc7a2d5a959334f7195571a3e1db669ed7667a28.tar.gz gitea-fc7a2d5a959334f7195571a3e1db669ed7667a28.zip |
Add support for HEAD requests in Maven registry (#21834)
Related #18543
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/context/context.go | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/modules/context/context.go b/modules/context/context.go index 697eb76904..47368bb280 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -349,9 +349,11 @@ func (ctx *Context) RespHeader() http.Header { type ServeHeaderOptions struct { ContentType string // defaults to "application/octet-stream" ContentTypeCharset string + ContentLength *int64 Disposition string // defaults to "attachment" Filename string CacheDuration time.Duration // defaults to 5 minutes + LastModified time.Time } // SetServeHeaders sets necessary content serve headers @@ -369,6 +371,10 @@ func (ctx *Context) SetServeHeaders(opts *ServeHeaderOptions) { header.Set("Content-Type", contentType) header.Set("X-Content-Type-Options", "nosniff") + if opts.ContentLength != nil { + header.Set("Content-Length", strconv.FormatInt(*opts.ContentLength, 10)) + } + if opts.Filename != "" { disposition := opts.Disposition if disposition == "" { @@ -385,14 +391,16 @@ func (ctx *Context) SetServeHeaders(opts *ServeHeaderOptions) { duration = 5 * time.Minute } httpcache.AddCacheControlToHeader(header, duration) + + if !opts.LastModified.IsZero() { + header.Set("Last-Modified", opts.LastModified.UTC().Format(http.TimeFormat)) + } } // ServeContent serves content to http request -func (ctx *Context) ServeContent(name string, r io.ReadSeeker, modTime time.Time) { - ctx.SetServeHeaders(&ServeHeaderOptions{ - Filename: name, - }) - http.ServeContent(ctx.Resp, ctx.Req, name, modTime, r) +func (ctx *Context) ServeContent(r io.ReadSeeker, opts *ServeHeaderOptions) { + ctx.SetServeHeaders(opts) + http.ServeContent(ctx.Resp, ctx.Req, opts.Filename, opts.LastModified, r) } // UploadStream returns the request body or the first form file |