7
7
uploadablepkg "github.com/cirruslabs/cirrus-cli/internal/agent/http_cache/azureblob/uploadable"
8
8
"github.com/cirruslabs/cirrus-cli/pkg/api"
9
9
"github.com/go-chi/render"
10
+ "io"
10
11
"net/http"
11
12
"strconv"
12
13
)
@@ -35,6 +36,15 @@ func (azureBlob *AzureBlob) putBlobAbstract(writer http.ResponseWriter, request
35
36
func (azureBlob * AzureBlob ) putBlob (writer http.ResponseWriter , request * http.Request ) {
36
37
key := request .PathValue ("key" )
37
38
39
+ // Parse the Content-Length header
40
+ contentLength , err := strconv .ParseUint (request .Header .Get ("Content-Length" ), 10 , 64 )
41
+ if err != nil {
42
+ fail (writer , request , http .StatusBadRequest , "failed to parse the Content-Length header value" ,
43
+ "key" , key , "err" , err , "value" , contentLength )
44
+
45
+ return
46
+ }
47
+
38
48
// Generate cache upload URL
39
49
generateCacheUploadURLResponse , err := client .CirrusClient .GenerateCacheUploadURL (
40
50
request .Context (),
@@ -60,6 +70,9 @@ func (azureBlob *AzureBlob) putBlob(writer http.ResponseWriter, request *http.Re
60
70
return
61
71
}
62
72
73
+ // Content-Length is required to avoid HTTP 411
74
+ req .ContentLength = int64 (contentLength )
75
+
63
76
resp , err := http .DefaultClient .Do (req )
64
77
if err != nil {
65
78
fail (writer , request , http .StatusInternalServerError , "failed to perform request to proxy " +
@@ -153,6 +166,9 @@ func (azureBlob *AzureBlob) putBlock(writer http.ResponseWriter, request *http.R
153
166
return
154
167
}
155
168
169
+ // Content-Length is pre-signed, so we need to provide it
170
+ req .ContentLength = int64 (contentLength )
171
+
156
172
resp , err := http .DefaultClient .Do (req )
157
173
if err != nil {
158
174
fail (writer , request , http .StatusInternalServerError , "failed to perform request to proxy " +
0 commit comments