@@ -21,6 +21,7 @@ import (
2121 "code.gitea.io/gitea/modules/httplib"
2222 "code.gitea.io/gitea/modules/json"
2323 "code.gitea.io/gitea/modules/log"
24+ "code.gitea.io/gitea/modules/optional"
2425 packages_module "code.gitea.io/gitea/modules/packages"
2526 container_module "code.gitea.io/gitea/modules/packages/container"
2627 "code.gitea.io/gitea/modules/setting"
@@ -50,7 +51,7 @@ type containerHeaders struct {
5051 Range string
5152 Location string
5253 ContentType string
53- ContentLength int64
54+ ContentLength optional. Option [ int64 ]
5455}
5556
5657// https://github.com/opencontainers/distribution-spec/blob/main/spec.md#legacy-docker-support-http-headers
@@ -64,8 +65,8 @@ func setResponseHeaders(resp http.ResponseWriter, h *containerHeaders) {
6465 if h .ContentType != "" {
6566 resp .Header ().Set ("Content-Type" , h .ContentType )
6667 }
67- if h .ContentLength != 0 {
68- resp .Header ().Set ("Content-Length" , strconv .FormatInt (h .ContentLength , 10 ))
68+ if h .ContentLength . Has () {
69+ resp .Header ().Set ("Content-Length" , strconv .FormatInt (h .ContentLength . Value () , 10 ))
6970 }
7071 if h .UploadUUID != "" {
7172 resp .Header ().Set ("Docker-Upload-Uuid" , h .UploadUUID )
@@ -505,7 +506,7 @@ func HeadBlob(ctx *context.Context) {
505506
506507 setResponseHeaders (ctx .Resp , & containerHeaders {
507508 ContentDigest : blob .Properties .GetByName (container_module .PropertyDigest ),
508- ContentLength : blob .Blob .Size ,
509+ ContentLength : optional . Some ( blob .Blob .Size ) ,
509510 Status : http .StatusOK ,
510511 })
511512}
@@ -644,7 +645,7 @@ func HeadManifest(ctx *context.Context) {
644645 setResponseHeaders (ctx .Resp , & containerHeaders {
645646 ContentDigest : manifest .Properties .GetByName (container_module .PropertyDigest ),
646647 ContentType : manifest .Properties .GetByName (container_module .PropertyMediaType ),
647- ContentLength : manifest .Blob .Size ,
648+ ContentLength : optional . Some ( manifest .Blob .Size ) ,
648649 Status : http .StatusOK ,
649650 })
650651}
@@ -708,14 +709,14 @@ func serveBlob(ctx *context.Context, pfd *packages_model.PackageFileDescriptor)
708709 headers := & containerHeaders {
709710 ContentDigest : pfd .Properties .GetByName (container_module .PropertyDigest ),
710711 ContentType : pfd .Properties .GetByName (container_module .PropertyMediaType ),
711- ContentLength : pfd .Blob .Size ,
712+ ContentLength : optional . Some ( pfd .Blob .Size ) ,
712713 Status : http .StatusOK ,
713714 }
714715
715716 if u != nil {
716717 headers .Status = http .StatusTemporaryRedirect
717718 headers .Location = u .String ()
718- headers .ContentLength = 0 // do not set Content-Length for redirect responses
719+ headers .ContentLength = optional . None [ int64 ]() // do not set Content-Length for redirect responses
719720 setResponseHeaders (ctx .Resp , headers )
720721 return
721722 }
0 commit comments