Skip to content

Commit

Permalink
Multipart upload - Fix empty nodeId response in completeMultipartUpload
Browse files Browse the repository at this point in the history
  • Loading branch information
yahavi committed Mar 11, 2024
1 parent f35f6dc commit ff1e107
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions artifactory/services/utils/multipartupload.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ const (
aborted completionStatus = "ABORTED"

// API constants
uploadsApi = "/api/v1/uploads/"
routeToHeader = "X-JFrog-Route-To"
uploadsApi = "/api/v1/uploads/"
routeToHeader = "X-JFrog-Route-To"
artifactoryNodeId = "X-Artifactory-Node-Id"

// Sizes and limits constants
MaxMultipartUploadFileSize = SizeTiB * 5
Expand Down Expand Up @@ -363,7 +364,7 @@ func (mu *MultipartUpload) completeMultipartUpload(logMsgPrefix, sha1 string, mu
return "", err
}
log.Debug("Artifactory response:", string(body), resp.Status)
return resp.Header.Get(routeToHeader), errorutils.CheckResponseStatusWithBody(resp, body, http.StatusAccepted)
return resp.Header.Get(artifactoryNodeId), errorutils.CheckResponseStatusWithBody(resp, body, http.StatusAccepted)
}

func (mu *MultipartUpload) status(logMsgPrefix string, multipartUploadClientWithNodeId *httputils.HttpClientDetails) (status statusResponse, err error) {
Expand Down Expand Up @@ -426,7 +427,7 @@ func parseMultipartUploadStatus(status statusResponse) (shouldKeepPolling, shoul
return true, false, nil
case retryableError:
// Retryable error was received - stop polling and rerun the /complete API again
log.Warn("received error upon multipart upload completion process: '%s', retrying...", status.Error)
log.Warn(fmt.Printf("received error upon multipart upload completion process: '%s', retrying...", status.Error))
return false, true, nil
case finished, aborted:
// Upload finished or aborted
Expand Down
4 changes: 2 additions & 2 deletions artifactory/services/utils/multipartupload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ func TestCompleteMultipartUpload(t *testing.T) {
assert.Equal(t, "/api/v1/uploads/complete", r.URL.Path)
assert.Equal(t, fmt.Sprintf("sha1=%s", sha1), r.URL.RawQuery)

// Add the "X-JFrog-Route-To" header to the response
w.Header().Add(routeToHeader, nodeId)
// Add the "X-Artifactory-Node-Id" header to the response
w.Header().Add(artifactoryNodeId, nodeId)

// Send response 202 Accepted
w.WriteHeader(http.StatusAccepted)
Expand Down

0 comments on commit ff1e107

Please sign in to comment.