Browse Source

add HeadBucket

pull/693/head
Chris Lu 7 years ago
parent
commit
feea33d5e0
  1. 28
      weed/s3api/s3api_bucket_handlers.go
  2. 6
      weed/s3api/s3api_errors.go
  3. 4
      weed/s3api/s3api_server.go

28
weed/s3api/s3api_bucket_handlers.go

@ -136,3 +136,31 @@ func (s3a *S3ApiServer) DeleteBucketHandler(w http.ResponseWriter, r *http.Reque
writeResponse(w, http.StatusNoContent, nil, mimeNone) writeResponse(w, http.StatusNoContent, nil, mimeNone)
} }
func (s3a *S3ApiServer) HeadBucketHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
bucket := vars["bucket"]
err := s3a.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
request := &filer_pb.LookupDirectoryEntryRequest{
Directory: s3a.option.BucketsPath,
Name: bucket,
}
glog.V(1).Infof("lookup bucket: %v", request)
if _, err := client.LookupDirectoryEntry(context.Background(), request); err != nil {
return fmt.Errorf("lookup bucket %s/%s: %v", s3a.option.BucketsPath, bucket, err)
}
return nil
})
if err != nil {
writeErrorResponse(w, ErrNoSuchBucket, r.URL)
return
}
writeSuccessResponseEmpty(w)
}

6
weed/s3api/s3api_errors.go

@ -32,6 +32,7 @@ const (
ErrBucketAlreadyExists ErrBucketAlreadyExists
ErrBucketAlreadyOwnedByYou ErrBucketAlreadyOwnedByYou
ErrInvalidBucketName ErrInvalidBucketName
ErrNoSuchBucket
ErrInternalError ErrInternalError
) )
@ -63,6 +64,11 @@ var errorCodeResponse = map[ErrorCode]APIError{
Description: "The specified bucket is not valid.", Description: "The specified bucket is not valid.",
HTTPStatusCode: http.StatusBadRequest, HTTPStatusCode: http.StatusBadRequest,
}, },
ErrNoSuchBucket: {
Code: "NoSuchBucket",
Description: "The specified bucket does not exist",
HTTPStatusCode: http.StatusNotFound,
},
ErrInternalError: { ErrInternalError: {
Code: "InternalError", Code: "InternalError",
Description: "We encountered an internal error, please try again.", Description: "We encountered an internal error, please try again.",

4
weed/s3api/s3api_server.go

@ -46,6 +46,8 @@ func (s3a *S3ApiServer) registerRouter(router *mux.Router) {
bucket.Methods("PUT").HandlerFunc(s3a.PutBucketHandler) bucket.Methods("PUT").HandlerFunc(s3a.PutBucketHandler)
// DeleteBucket // DeleteBucket
bucket.Methods("DELETE").HandlerFunc(s3a.DeleteBucketHandler) bucket.Methods("DELETE").HandlerFunc(s3a.DeleteBucketHandler)
// HeadBucket
bucket.Methods("HEAD").HandlerFunc(s3a.HeadBucketHandler)
/* /*
// HeadObject // HeadObject
@ -78,8 +80,6 @@ func (s3a *S3ApiServer) registerRouter(router *mux.Router) {
bucket.Methods("GET").HandlerFunc(s3a.ListObjectsV2Handler).Queries("list-type", "2") bucket.Methods("GET").HandlerFunc(s3a.ListObjectsV2Handler).Queries("list-type", "2")
// ListObjectsV1 (Legacy) // ListObjectsV1 (Legacy)
bucket.Methods("GET").HandlerFunc(s3a.ListObjectsV1Handler) bucket.Methods("GET").HandlerFunc(s3a.ListObjectsV1Handler)
// HeadBucket
bucket.Methods("HEAD").HandlerFunc(s3a.HeadBucketHandler)
// DeleteMultipleObjects // DeleteMultipleObjects
bucket.Methods("POST").HandlerFunc(s3a.DeleteMultipleObjectsHandler).Queries("delete", "") bucket.Methods("POST").HandlerFunc(s3a.DeleteMultipleObjectsHandler).Queries("delete", "")

Loading…
Cancel
Save