@@ -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"
2425packages_module "code.gitea.io/gitea/modules/packages"
2526container_module "code.gitea.io/gitea/modules/packages/container"
2627"code.gitea.io/gitea/modules/setting"
@@ -50,7 +51,7 @@ type containerHeaders struct {
5051Range string
5152Location string
5253ContentType 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) {
6465if h .ContentType != "" {
6566resp .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}
7071if h .UploadUUID != "" {
7172resp .Header ().Set ("Docker-Upload-Uuid" , h .UploadUUID )
@@ -505,7 +506,7 @@ func HeadBlob(ctx *context.Context) {
505506
506507setResponseHeaders (ctx .Resp , & containerHeaders {
507508ContentDigest : blob .Properties .GetByName (container_module .PropertyDigest ),
508- ContentLength : blob .Blob .Size ,
509+ ContentLength : optional . Some ( blob .Blob .Size ) ,
509510Status : http .StatusOK ,
510511})
511512}
@@ -644,7 +645,7 @@ func HeadManifest(ctx *context.Context) {
644645setResponseHeaders (ctx .Resp , & containerHeaders {
645646ContentDigest : manifest .Properties .GetByName (container_module .PropertyDigest ),
646647ContentType : manifest .Properties .GetByName (container_module .PropertyMediaType ),
647- ContentLength : manifest .Blob .Size ,
648+ ContentLength : optional . Some ( manifest .Blob .Size ) ,
648649Status : http .StatusOK ,
649650})
650651}
@@ -708,14 +709,14 @@ func serveBlob(ctx *context.Context, pfd *packages_model.PackageFileDescriptor)
708709headers := & containerHeaders {
709710ContentDigest : pfd .Properties .GetByName (container_module .PropertyDigest ),
710711ContentType : pfd .Properties .GetByName (container_module .PropertyMediaType ),
711- ContentLength : pfd .Blob .Size ,
712+ ContentLength : optional . Some ( pfd .Blob .Size ) ,
712713Status : http .StatusOK ,
713714}
714715
715716if u != nil {
716717headers .Status = http .StatusTemporaryRedirect
717718headers .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
719720setResponseHeaders (ctx .Resp , headers )
720721return
721722}
0 commit comments