mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-11-10 07:04:47 +08:00
When an S3 upload has a mismatched Content-MD5 header, SeaweedFS was incorrectly returning a 500 Internal Server Error instead of the proper 400 Bad Request with error code BadDigest (per AWS S3 specification). Changes: - Created weed/util/constants/filer.go with error message constants - Added ErrMsgBadDigest constant for MD5 mismatch errors - Added ErrMsgOperationNotPermitted constant for WORM permission errors - Added ErrBadDigest error code with proper 400 status code mapping - Updated filerErrorToS3Error() to detect MD5 mismatch and return ErrBadDigest - Updated filer autoChunk() to return 400 Bad Request for MD5 mismatch - Refactored error handling to use switch statement for better readability - Ordered error checks with exact matches first for better maintainability - Updated all error handling to use centralized constants - Added comprehensive unit tests All error messages now use constants from a single location for better maintainability and consistency. Constants placed in util package to avoid architectural dependency issues. Fixes #7305
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/seaweedfs/seaweedfs/weed/s3api/s3err"
|
||||
"github.com/seaweedfs/seaweedfs/weed/security"
|
||||
weed_server "github.com/seaweedfs/seaweedfs/weed/server"
|
||||
"github.com/seaweedfs/seaweedfs/weed/util/constants"
|
||||
stats_collect "github.com/seaweedfs/seaweedfs/weed/stats"
|
||||
)
|
||||
|
||||
@@ -380,6 +381,8 @@ func setEtag(w http.ResponseWriter, etag string) {
|
||||
|
||||
func filerErrorToS3Error(errString string) s3err.ErrorCode {
|
||||
switch {
|
||||
case errString == constants.ErrMsgBadDigest:
|
||||
return s3err.ErrBadDigest
|
||||
case strings.HasPrefix(errString, "existing ") && strings.HasSuffix(errString, "is a directory"):
|
||||
return s3err.ErrExistingObjectIsDirectory
|
||||
case strings.HasSuffix(errString, "is a file"):
|
||||
|
||||
Reference in New Issue
Block a user