@@ -21,6 +21,7 @@ import (
21
21
"code.gitea.io/gitea/modules/httplib"
22
22
"code.gitea.io/gitea/modules/json"
23
23
"code.gitea.io/gitea/modules/log"
24
+ "code.gitea.io/gitea/modules/optional"
24
25
packages_module "code.gitea.io/gitea/modules/packages"
25
26
container_module "code.gitea.io/gitea/modules/packages/container"
26
27
"code.gitea.io/gitea/modules/setting"
@@ -50,7 +51,7 @@ type containerHeaders struct {
50
51
Range string
51
52
Location string
52
53
ContentType string
53
- ContentLength int64
54
+ ContentLength optional. Option [ int64 ]
54
55
}
55
56
56
57
// 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) {
64
65
if h .ContentType != "" {
65
66
resp .Header ().Set ("Content-Type" , h .ContentType )
66
67
}
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 ))
69
70
}
70
71
if h .UploadUUID != "" {
71
72
resp .Header ().Set ("Docker-Upload-Uuid" , h .UploadUUID )
@@ -505,7 +506,7 @@ func HeadBlob(ctx *context.Context) {
505
506
506
507
setResponseHeaders (ctx .Resp , & containerHeaders {
507
508
ContentDigest : blob .Properties .GetByName (container_module .PropertyDigest ),
508
- ContentLength : blob .Blob .Size ,
509
+ ContentLength : optional . Some ( blob .Blob .Size ) ,
509
510
Status : http .StatusOK ,
510
511
})
511
512
}
@@ -644,7 +645,7 @@ func HeadManifest(ctx *context.Context) {
644
645
setResponseHeaders (ctx .Resp , & containerHeaders {
645
646
ContentDigest : manifest .Properties .GetByName (container_module .PropertyDigest ),
646
647
ContentType : manifest .Properties .GetByName (container_module .PropertyMediaType ),
647
- ContentLength : manifest .Blob .Size ,
648
+ ContentLength : optional . Some ( manifest .Blob .Size ) ,
648
649
Status : http .StatusOK ,
649
650
})
650
651
}
@@ -708,14 +709,14 @@ func serveBlob(ctx *context.Context, pfd *packages_model.PackageFileDescriptor)
708
709
headers := & containerHeaders {
709
710
ContentDigest : pfd .Properties .GetByName (container_module .PropertyDigest ),
710
711
ContentType : pfd .Properties .GetByName (container_module .PropertyMediaType ),
711
- ContentLength : pfd .Blob .Size ,
712
+ ContentLength : optional . Some ( pfd .Blob .Size ) ,
712
713
Status : http .StatusOK ,
713
714
}
714
715
715
716
if u != nil {
716
717
headers .Status = http .StatusTemporaryRedirect
717
718
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
719
720
setResponseHeaders (ctx .Resp , headers )
720
721
return
721
722
}
0 commit comments