Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: send Content-Length: 0 to the Object Storage when file is empty #5912

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading