diff --git a/cmd/handler-utils.go b/cmd/handler-utils.go index b4e85f312..1e4a9d039 100644 --- a/cmd/handler-utils.go +++ b/cmd/handler-utils.go @@ -238,7 +238,9 @@ func extractReqParams(r *http.Request) map[string]string { // Extract response elements to be sent with event notifiation. func extractRespElements(w http.ResponseWriter) map[string]string { - + if w == nil { + return map[string]string{} + } return map[string]string{ "requestId": w.Header().Get(xhttp.AmzRequestID), "content-length": w.Header().Get(xhttp.ContentLength), diff --git a/cmd/object-handlers-common.go b/cmd/object-handlers-common.go index fbcf4aef5..b2016d7f0 100644 --- a/cmd/object-handlers-common.go +++ b/cmd/object-handlers-common.go @@ -281,7 +281,7 @@ func setPutObjHeaders(w http.ResponseWriter, objInfo ObjectInfo, delete bool) { // deleteObject is a convenient wrapper to delete an object, this // is a common function to be called from object handlers and // web handlers. -func deleteObject(ctx context.Context, obj ObjectLayer, cache CacheObjectLayer, bucket, object string, r *http.Request, opts ObjectOptions) (objInfo ObjectInfo, err error) { +func deleteObject(ctx context.Context, obj ObjectLayer, cache CacheObjectLayer, bucket, object string, w http.ResponseWriter, r *http.Request, opts ObjectOptions) (objInfo ObjectInfo, err error) { deleteObject := obj.DeleteObject if cache != nil { deleteObject = cache.DeleteObject @@ -293,22 +293,24 @@ func deleteObject(ctx context.Context, obj ObjectLayer, cache CacheObjectLayer, if objInfo.DeleteMarker { // Notify object deleted marker event. sendEvent(eventArgs{ - EventName: event.ObjectRemovedDeleteMarkerCreated, - BucketName: bucket, - Object: objInfo, - ReqParams: extractReqParams(r), - UserAgent: r.UserAgent(), - Host: handlers.GetSourceIP(r), + EventName: event.ObjectRemovedDeleteMarkerCreated, + BucketName: bucket, + Object: objInfo, + ReqParams: extractReqParams(r), + RespElements: extractRespElements(w), + UserAgent: r.UserAgent(), + Host: handlers.GetSourceIP(r), }) } else { // Notify object deleted event. sendEvent(eventArgs{ - EventName: event.ObjectRemovedDelete, - BucketName: bucket, - Object: objInfo, - ReqParams: extractReqParams(r), - UserAgent: r.UserAgent(), - Host: handlers.GetSourceIP(r), + EventName: event.ObjectRemovedDelete, + BucketName: bucket, + Object: objInfo, + ReqParams: extractReqParams(r), + RespElements: extractRespElements(w), + UserAgent: r.UserAgent(), + Host: handlers.GetSourceIP(r), }) } } diff --git a/cmd/object-handlers.go b/cmd/object-handlers.go index 84e5fdd93..ca3433adc 100644 --- a/cmd/object-handlers.go +++ b/cmd/object-handlers.go @@ -2726,7 +2726,7 @@ func (api objectAPIHandlers) DeleteObjectHandler(w http.ResponseWriter, r *http. } // http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectDELETE.html - objInfo, err := deleteObject(ctx, objectAPI, api.CacheAPI(), bucket, object, r, opts) + objInfo, err := deleteObject(ctx, objectAPI, api.CacheAPI(), bucket, object, w, r, opts) if err != nil { switch err.(type) { case BucketNotFound: diff --git a/cmd/web-handlers.go b/cmd/web-handlers.go index 7eb4717bd..2e3ba3640 100644 --- a/cmd/web-handlers.go +++ b/cmd/web-handlers.go @@ -715,7 +715,7 @@ next: } } - _, err = deleteObject(ctx, objectAPI, web.CacheAPI(), args.BucketName, objectName, r, opts) + _, err = deleteObject(ctx, objectAPI, web.CacheAPI(), args.BucketName, objectName, nil, r, opts) logger.LogIf(ctx, err) continue } @@ -771,13 +771,35 @@ next: } // Deletes a list of objects. - _, errs := deleteObjects(ctx, args.BucketName, objects, opts) + deletedObjects, errs := deleteObjects(ctx, args.BucketName, objects, opts) for _, err := range errs { if err != nil { logger.LogIf(ctx, err) break next } } + // Notify deleted event for objects. + for _, dobj := range deletedObjects { + objInfo := ObjectInfo{ + Name: dobj.ObjectName, + VersionID: dobj.VersionID, + } + if dobj.DeleteMarker { + objInfo = ObjectInfo{ + Name: dobj.ObjectName, + DeleteMarker: dobj.DeleteMarker, + VersionID: dobj.DeleteMarkerVersionID, + } + } + sendEvent(eventArgs{ + EventName: event.ObjectRemovedDelete, + BucketName: args.BucketName, + Object: objInfo, + ReqParams: extractReqParams(r), + UserAgent: r.UserAgent(), + Host: handlers.GetSourceIP(r), + }) + } } }