diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2020-06-11 10:37:19 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-11 10:37:19 -0700 |
| commit | 63a1db64c5eaf80739163ead31f168d9c634edb6 (patch) | |
| tree | ee171507f99a0bdb358d02c1e2fb2cad1a8ee45b | |
| parent | 628b27ef3b4cf8c1c894430e0d40b0bc1de8ba96 (diff) | |
| parent | 283b749ff1af05cfb60df614b1710bfc021b425d (diff) | |
| download | seaweedfs-63a1db64c5eaf80739163ead31f168d9c634edb6.tar.xz seaweedfs-63a1db64c5eaf80739163ead31f168d9c634edb6.zip | |
Merge pull request #1358 from DXist/s3fixes
Return NotSuchKey error code for bucket S3 DeleteObject method
| -rw-r--r-- | weed/s3api/s3api_errors.go | 6 | ||||
| -rw-r--r-- | weed/s3api/s3api_handlers.go | 9 | ||||
| -rw-r--r-- | weed/s3api/s3api_object_handlers.go | 6 |
3 files changed, 17 insertions, 4 deletions
diff --git a/weed/s3api/s3api_errors.go b/weed/s3api/s3api_errors.go index 3f97c73cb..ff411f276 100644 --- a/weed/s3api/s3api_errors.go +++ b/weed/s3api/s3api_errors.go @@ -33,6 +33,7 @@ const ( ErrBucketAlreadyExists ErrBucketAlreadyOwnedByYou ErrNoSuchBucket + ErrNoSuchKey ErrNoSuchUpload ErrInvalidBucketName ErrInvalidDigest @@ -134,6 +135,11 @@ var errorCodeResponse = map[ErrorCode]APIError{ Description: "The specified bucket does not exist", HTTPStatusCode: http.StatusNotFound, }, + ErrNoSuchKey: { + Code: "NoSuchKey", + Description: "The specified key does not exist.", + HTTPStatusCode: http.StatusNotFound, + }, ErrNoSuchUpload: { Code: "NoSuchUpload", Description: "The specified multipart upload does not exist. The upload ID may be invalid, or the upload may have been aborted or completed.", diff --git a/weed/s3api/s3api_handlers.go b/weed/s3api/s3api_handlers.go index 45a7cbc2e..7ef676400 100644 --- a/weed/s3api/s3api_handlers.go +++ b/weed/s3api/s3api_handlers.go @@ -7,6 +7,7 @@ import ( "fmt" "net/http" "net/url" + "strconv" "time" "google.golang.org/grpc" @@ -76,13 +77,19 @@ func getRESTErrorResponse(err APIError, resource string) RESTErrorResponse { func writeResponse(w http.ResponseWriter, statusCode int, response []byte, mType mimeType) { setCommonHeaders(w) + if response != nil { + w.Header().Set("Content-Length", strconv.Itoa(len(response))) + } if mType != mimeNone { w.Header().Set("Content-Type", string(mType)) } w.WriteHeader(statusCode) if response != nil { glog.V(4).Infof("status %d %s: %s", statusCode, mType, string(response)) - w.Write(response) + _, err := w.Write(response) + if err != nil { + glog.V(0).Infof("write err: %v", err) + } w.(http.Flusher).Flush() } } diff --git a/weed/s3api/s3api_object_handlers.go b/weed/s3api/s3api_object_handlers.go index 300441ef2..87c3ce705 100644 --- a/weed/s3api/s3api_object_handlers.go +++ b/weed/s3api/s3api_object_handlers.go @@ -14,7 +14,7 @@ import ( "github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" - "github.com/chrislusf/seaweedfs/weed/server" + weed_server "github.com/chrislusf/seaweedfs/weed/server" "github.com/chrislusf/seaweedfs/weed/util" ) @@ -108,8 +108,8 @@ func (s3a *S3ApiServer) DeleteObjectHandler(w http.ResponseWriter, r *http.Reque destUrl := fmt.Sprintf("http://%s%s/%s%s", s3a.option.Filer, s3a.option.BucketsPath, bucket, object) - s3a.proxyToFiler(w, r, destUrl, func(proxyResonse *http.Response, w http.ResponseWriter) { - for k, v := range proxyResonse.Header { + s3a.proxyToFiler(w, r, destUrl, func(proxyResponse *http.Response, w http.ResponseWriter) { + for k, v := range proxyResponse.Header { w.Header()[k] = v } w.WriteHeader(http.StatusNoContent) |
