Skip to content

Commit

Permalink
fix: send Content-Length: 0 to the Object Storage when file is empty (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rangoo94 authored Oct 9, 2024
1 parent 6203fc8 commit 1180159
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions cmd/testworkflow-toolkit/artifacts/cloud_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ func (d *cloudUploader) getContentType(path string, size int64) string {
func (d *cloudUploader) putObject(url string, path string, file io.Reader, size int64) error {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
defer cancel()
if size == 0 {
// http.Request won't send Content-Length: 0, if the body is non-nil
file = nil
}
req, err := http.NewRequestWithContext(ctx, http.MethodPut, url, file)
if err != nil {
return err
Expand Down
11 changes: 9 additions & 2 deletions pkg/cloud/data/testworkflow/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ func (r *CloudOutputRepository) SaveLog(ctx context.Context, id, workflowName st
if err != nil {
return err
}
defer buffer.Cleanup()
bufferLen := buffer.Len()
if bufferLen == 0 {
// http.Request won't send Content-Length: 0, if the body is non-nil
buffer.Cleanup()
buffer = nil
} else {
defer buffer.Cleanup()
}
url, err := r.PresignSaveLog(ctx, id, workflowName)
if err != nil {
return err
Expand All @@ -75,7 +82,7 @@ func (r *CloudOutputRepository) SaveLog(ctx context.Context, id, workflowName st
return err
}
req.Header.Add("Content-Type", "application/octet-stream")
req.ContentLength = int64(buffer.Len())
req.ContentLength = int64(bufferLen)
res, err := r.httpClient.Do(req)
if err != nil {
return errors.Wrap(err, "failed to save file in cloud storage")
Expand Down

0 comments on commit 1180159

Please sign in to comment.