Skip to content

Commit 0b21ffd

Browse files
committed
Azure Blob API: make sure Content-Length is set when making S3 PUT
1 parent 2090b45 commit 0b21ffd

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

internal/agent/http_cache/azureblob/putblob.go

+15
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ func (azureBlob *AzureBlob) putBlobAbstract(writer http.ResponseWriter, request
3535
func (azureBlob *AzureBlob) putBlob(writer http.ResponseWriter, request *http.Request) {
3636
key := request.PathValue("key")
3737

38+
// Parse the Content-Length header
39+
contentLength, err := strconv.ParseUint(request.Header.Get("Content-Length"), 10, 64)
40+
if err != nil {
41+
fail(writer, request, http.StatusBadRequest, "failed to parse the Content-Length header value",
42+
"key", key, "err", err, "value", contentLength)
43+
44+
return
45+
}
46+
3847
// Generate cache upload URL
3948
generateCacheUploadURLResponse, err := client.CirrusClient.GenerateCacheUploadURL(
4049
request.Context(),
@@ -60,6 +69,9 @@ func (azureBlob *AzureBlob) putBlob(writer http.ResponseWriter, request *http.Re
6069
return
6170
}
6271

72+
// Content-Length is required to avoid HTTP 411
73+
req.ContentLength = int64(contentLength)
74+
6375
resp, err := http.DefaultClient.Do(req)
6476
if err != nil {
6577
fail(writer, request, http.StatusInternalServerError, "failed to perform request to proxy "+
@@ -153,6 +165,9 @@ func (azureBlob *AzureBlob) putBlock(writer http.ResponseWriter, request *http.R
153165
return
154166
}
155167

168+
// Content-Length is pre-signed, so we need to provide it
169+
req.ContentLength = int64(contentLength)
170+
156171
resp, err := http.DefaultClient.Do(req)
157172
if err != nil {
158173
fail(writer, request, http.StatusInternalServerError, "failed to perform request to proxy "+

0 commit comments

Comments
 (0)