Skip to content

Commit 1dda31e

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

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

internal/agent/http_cache/azureblob/putblob.go

+16
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
uploadablepkg "github.com/cirruslabs/cirrus-cli/internal/agent/http_cache/azureblob/uploadable"
88
"github.com/cirruslabs/cirrus-cli/pkg/api"
99
"github.com/go-chi/render"
10+
"io"
1011
"net/http"
1112
"strconv"
1213
)
@@ -35,6 +36,15 @@ func (azureBlob *AzureBlob) putBlobAbstract(writer http.ResponseWriter, request
3536
func (azureBlob *AzureBlob) putBlob(writer http.ResponseWriter, request *http.Request) {
3637
key := request.PathValue("key")
3738

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+
3848
// Generate cache upload URL
3949
generateCacheUploadURLResponse, err := client.CirrusClient.GenerateCacheUploadURL(
4050
request.Context(),
@@ -60,6 +70,9 @@ func (azureBlob *AzureBlob) putBlob(writer http.ResponseWriter, request *http.Re
6070
return
6171
}
6272

73+
// Content-Length is required to avoid HTTP 411
74+
req.ContentLength = int64(contentLength)
75+
6376
resp, err := http.DefaultClient.Do(req)
6477
if err != nil {
6578
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
153166
return
154167
}
155168

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

0 commit comments

Comments
 (0)