Merge pull request #1358 from DXist/s3fixes

Return NotSuchKey error code for bucket S3 DeleteObject method
This commit is contained in:
Chris Lu 2020-06-11 10:37:19 -07:00 committed by GitHub
commit 63a1db64c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 4 deletions

View file

@ -33,6 +33,7 @@ const (
ErrBucketAlreadyExists ErrBucketAlreadyExists
ErrBucketAlreadyOwnedByYou ErrBucketAlreadyOwnedByYou
ErrNoSuchBucket ErrNoSuchBucket
ErrNoSuchKey
ErrNoSuchUpload ErrNoSuchUpload
ErrInvalidBucketName ErrInvalidBucketName
ErrInvalidDigest ErrInvalidDigest
@ -134,6 +135,11 @@ var errorCodeResponse = map[ErrorCode]APIError{
Description: "The specified bucket does not exist", Description: "The specified bucket does not exist",
HTTPStatusCode: http.StatusNotFound, HTTPStatusCode: http.StatusNotFound,
}, },
ErrNoSuchKey: {
Code: "NoSuchKey",
Description: "The specified key does not exist.",
HTTPStatusCode: http.StatusNotFound,
},
ErrNoSuchUpload: { ErrNoSuchUpload: {
Code: "NoSuchUpload", 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.", Description: "The specified multipart upload does not exist. The upload ID may be invalid, or the upload may have been aborted or completed.",

View file

@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
"strconv"
"time" "time"
"google.golang.org/grpc" "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) { func writeResponse(w http.ResponseWriter, statusCode int, response []byte, mType mimeType) {
setCommonHeaders(w) setCommonHeaders(w)
if response != nil {
w.Header().Set("Content-Length", strconv.Itoa(len(response)))
}
if mType != mimeNone { if mType != mimeNone {
w.Header().Set("Content-Type", string(mType)) w.Header().Set("Content-Type", string(mType))
} }
w.WriteHeader(statusCode) w.WriteHeader(statusCode)
if response != nil { if response != nil {
glog.V(4).Infof("status %d %s: %s", statusCode, mType, string(response)) 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() w.(http.Flusher).Flush()
} }
} }

View file

@ -14,7 +14,7 @@ import (
"github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb" "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" "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", destUrl := fmt.Sprintf("http://%s%s/%s%s",
s3a.option.Filer, s3a.option.BucketsPath, bucket, object) s3a.option.Filer, s3a.option.BucketsPath, bucket, object)
s3a.proxyToFiler(w, r, destUrl, func(proxyResonse *http.Response, w http.ResponseWriter) { s3a.proxyToFiler(w, r, destUrl, func(proxyResponse *http.Response, w http.ResponseWriter) {
for k, v := range proxyResonse.Header { for k, v := range proxyResponse.Header {
w.Header()[k] = v w.Header()[k] = v
} }
w.WriteHeader(http.StatusNoContent) w.WriteHeader(http.StatusNoContent)