|
|
@ -117,7 +117,6 @@ func (api objectAPIHandlers) GetObjectHandler(w http.ResponseWriter, r *http.Req |
|
|
|
|
|
|
|
|
|
|
|
objInfo, err := objectAPI.GetObjectInfo(bucket, object) |
|
|
|
objInfo, err := objectAPI.GetObjectInfo(bucket, object) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
errorIf(err, "Unable to fetch object info.") |
|
|
|
|
|
|
|
apiErr := toAPIErrorCode(err) |
|
|
|
apiErr := toAPIErrorCode(err) |
|
|
|
if apiErr == ErrNoSuchKey { |
|
|
|
if apiErr == ErrNoSuchKey { |
|
|
|
apiErr = errAllowableObjectNotFound(bucket, r) |
|
|
|
apiErr = errAllowableObjectNotFound(bucket, r) |
|
|
@ -245,7 +244,6 @@ func (api objectAPIHandlers) HeadObjectHandler(w http.ResponseWriter, r *http.Re |
|
|
|
|
|
|
|
|
|
|
|
objInfo, err := objectAPI.GetObjectInfo(bucket, object) |
|
|
|
objInfo, err := objectAPI.GetObjectInfo(bucket, object) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
errorIf(err, "Unable to fetch object info.") |
|
|
|
|
|
|
|
apiErr := toAPIErrorCode(err) |
|
|
|
apiErr := toAPIErrorCode(err) |
|
|
|
if apiErr == ErrNoSuchKey { |
|
|
|
if apiErr == ErrNoSuchKey { |
|
|
|
apiErr = errAllowableObjectNotFound(bucket, r) |
|
|
|
apiErr = errAllowableObjectNotFound(bucket, r) |
|
|
@ -393,7 +391,6 @@ func (api objectAPIHandlers) CopyObjectHandler(w http.ResponseWriter, r *http.Re |
|
|
|
|
|
|
|
|
|
|
|
objInfo, err := objectAPI.GetObjectInfo(srcBucket, srcObject) |
|
|
|
objInfo, err := objectAPI.GetObjectInfo(srcBucket, srcObject) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
errorIf(err, "Unable to fetch object info.") |
|
|
|
|
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -488,7 +485,6 @@ func (api objectAPIHandlers) PutObjectHandler(w http.ResponseWriter, r *http.Req |
|
|
|
// Get Content-Md5 sent by client and verify if valid
|
|
|
|
// Get Content-Md5 sent by client and verify if valid
|
|
|
|
md5Bytes, err := checkValidMD5(r.Header.Get("Content-Md5")) |
|
|
|
md5Bytes, err := checkValidMD5(r.Header.Get("Content-Md5")) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
errorIf(err, "Unable to validate content-md5 format.") |
|
|
|
|
|
|
|
writeErrorResponse(w, ErrInvalidDigest, r.URL) |
|
|
|
writeErrorResponse(w, ErrInvalidDigest, r.URL) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -500,7 +496,6 @@ func (api objectAPIHandlers) PutObjectHandler(w http.ResponseWriter, r *http.Req |
|
|
|
sizeStr := r.Header.Get("x-amz-decoded-content-length") |
|
|
|
sizeStr := r.Header.Get("x-amz-decoded-content-length") |
|
|
|
size, err = strconv.ParseInt(sizeStr, 10, 64) |
|
|
|
size, err = strconv.ParseInt(sizeStr, 10, 64) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
errorIf(err, "Unable to parse `x-amz-decoded-content-length` into its integer value", sizeStr) |
|
|
|
|
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -619,7 +614,6 @@ func (api objectAPIHandlers) PutObjectHandler(w http.ResponseWriter, r *http.Req |
|
|
|
|
|
|
|
|
|
|
|
objInfo, err := objectAPI.PutObject(bucket, object, hashReader, metadata) |
|
|
|
objInfo, err := objectAPI.PutObject(bucket, object, hashReader, metadata) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
errorIf(err, "Unable to create an object. %s", r.URL.Path) |
|
|
|
|
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -692,7 +686,6 @@ func (api objectAPIHandlers) NewMultipartUploadHandler(w http.ResponseWriter, r |
|
|
|
|
|
|
|
|
|
|
|
uploadID, err := objectAPI.NewMultipartUpload(bucket, object, metadata) |
|
|
|
uploadID, err := objectAPI.NewMultipartUpload(bucket, object, metadata) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
errorIf(err, "Unable to initiate new multipart upload id.") |
|
|
|
|
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -767,7 +760,6 @@ func (api objectAPIHandlers) CopyObjectPartHandler(w http.ResponseWriter, r *htt |
|
|
|
|
|
|
|
|
|
|
|
objInfo, err := objectAPI.GetObjectInfo(srcBucket, srcObject) |
|
|
|
objInfo, err := objectAPI.GetObjectInfo(srcBucket, srcObject) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
errorIf(err, "Unable to fetch object info.") |
|
|
|
|
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -809,7 +801,6 @@ func (api objectAPIHandlers) CopyObjectPartHandler(w http.ResponseWriter, r *htt |
|
|
|
partInfo, err := objectAPI.CopyObjectPart(srcBucket, srcObject, dstBucket, |
|
|
|
partInfo, err := objectAPI.CopyObjectPart(srcBucket, srcObject, dstBucket, |
|
|
|
dstObject, uploadID, partID, startOffset, length, nil) |
|
|
|
dstObject, uploadID, partID, startOffset, length, nil) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
errorIf(err, "Unable to perform CopyObjectPart %s/%s", srcBucket, srcObject) |
|
|
|
|
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -861,7 +852,6 @@ func (api objectAPIHandlers) PutObjectPartHandler(w http.ResponseWriter, r *http |
|
|
|
sizeStr := r.Header.Get("x-amz-decoded-content-length") |
|
|
|
sizeStr := r.Header.Get("x-amz-decoded-content-length") |
|
|
|
size, err = strconv.ParseInt(sizeStr, 10, 64) |
|
|
|
size, err = strconv.ParseInt(sizeStr, 10, 64) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
errorIf(err, "Unable to parse `x-amz-decoded-content-length` into its integer value", sizeStr) |
|
|
|
|
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -940,7 +930,6 @@ func (api objectAPIHandlers) PutObjectPartHandler(w http.ResponseWriter, r *http |
|
|
|
|
|
|
|
|
|
|
|
hashReader, err := hash.NewReader(reader, size, md5hex, sha256hex) |
|
|
|
hashReader, err := hash.NewReader(reader, size, md5hex, sha256hex) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
errorIf(err, "Unable to create object part.") |
|
|
|
|
|
|
|
// Verify if the underlying error is signature mismatch.
|
|
|
|
// Verify if the underlying error is signature mismatch.
|
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
return |
|
|
|
return |
|
|
@ -948,7 +937,6 @@ func (api objectAPIHandlers) PutObjectPartHandler(w http.ResponseWriter, r *http |
|
|
|
|
|
|
|
|
|
|
|
partInfo, err := objectAPI.PutObjectPart(bucket, object, uploadID, partID, hashReader) |
|
|
|
partInfo, err := objectAPI.PutObjectPart(bucket, object, uploadID, partID, hashReader) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
errorIf(err, "Unable to create object part.") |
|
|
|
|
|
|
|
// Verify if the underlying error is signature mismatch.
|
|
|
|
// Verify if the underlying error is signature mismatch.
|
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
return |
|
|
|
return |
|
|
@ -979,7 +967,6 @@ func (api objectAPIHandlers) AbortMultipartUploadHandler(w http.ResponseWriter, |
|
|
|
|
|
|
|
|
|
|
|
uploadID, _, _, _ := getObjectResources(r.URL.Query()) |
|
|
|
uploadID, _, _, _ := getObjectResources(r.URL.Query()) |
|
|
|
if err := objectAPI.AbortMultipartUpload(bucket, object, uploadID); err != nil { |
|
|
|
if err := objectAPI.AbortMultipartUpload(bucket, object, uploadID); err != nil { |
|
|
|
errorIf(err, "Unable to abort multipart upload.") |
|
|
|
|
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -1014,7 +1001,6 @@ func (api objectAPIHandlers) ListObjectPartsHandler(w http.ResponseWriter, r *ht |
|
|
|
} |
|
|
|
} |
|
|
|
listPartsInfo, err := objectAPI.ListObjectParts(bucket, object, uploadID, partNumberMarker, maxParts) |
|
|
|
listPartsInfo, err := objectAPI.ListObjectParts(bucket, object, uploadID, partNumberMarker, maxParts) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
errorIf(err, "Unable to list uploaded parts.") |
|
|
|
|
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
writeErrorResponse(w, toAPIErrorCode(err), r.URL) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -1047,13 +1033,11 @@ func (api objectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWrite |
|
|
|
|
|
|
|
|
|
|
|
completeMultipartBytes, err := goioutil.ReadAll(r.Body) |
|
|
|
completeMultipartBytes, err := goioutil.ReadAll(r.Body) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
errorIf(err, "Unable to complete multipart upload.") |
|
|
|
|
|
|
|
writeErrorResponse(w, ErrInternalError, r.URL) |
|
|
|
writeErrorResponse(w, ErrInternalError, r.URL) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
complMultipartUpload := &CompleteMultipartUpload{} |
|
|
|
complMultipartUpload := &CompleteMultipartUpload{} |
|
|
|
if err = xml.Unmarshal(completeMultipartBytes, complMultipartUpload); err != nil { |
|
|
|
if err = xml.Unmarshal(completeMultipartBytes, complMultipartUpload); err != nil { |
|
|
|
errorIf(err, "Unable to parse complete multipart upload XML.") |
|
|
|
|
|
|
|
writeErrorResponse(w, ErrMalformedXML, r.URL) |
|
|
|
writeErrorResponse(w, ErrMalformedXML, r.URL) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
@ -1083,7 +1067,6 @@ func (api objectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWrite |
|
|
|
|
|
|
|
|
|
|
|
objInfo, err := objectAPI.CompleteMultipartUpload(bucket, object, uploadID, completeParts) |
|
|
|
objInfo, err := objectAPI.CompleteMultipartUpload(bucket, object, uploadID, completeParts) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
errorIf(err, "Unable to complete multipart upload.") |
|
|
|
|
|
|
|
err = errors.Cause(err) |
|
|
|
err = errors.Cause(err) |
|
|
|
switch oErr := err.(type) { |
|
|
|
switch oErr := err.(type) { |
|
|
|
case PartTooSmall: |
|
|
|
case PartTooSmall: |
|
|
@ -1102,7 +1085,6 @@ func (api objectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWrite |
|
|
|
response := generateCompleteMultpartUploadResponse(bucket, object, location, objInfo.ETag) |
|
|
|
response := generateCompleteMultpartUploadResponse(bucket, object, location, objInfo.ETag) |
|
|
|
encodedSuccessResponse := encodeResponse(response) |
|
|
|
encodedSuccessResponse := encodeResponse(response) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
errorIf(err, "Unable to parse CompleteMultipartUpload response") |
|
|
|
|
|
|
|
writeErrorResponse(w, ErrInternalError, r.URL) |
|
|
|
writeErrorResponse(w, ErrInternalError, r.URL) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|