mirror of
https://github.com/versity/versitygw.git
synced 2026-09-20 15:04:27 +00:00
fix: Fixes #247, Changed DeleteObjectTagging action successful response status from 200 to 204
This commit is contained in:
@@ -708,6 +708,7 @@ func (c S3ApiController) DeleteActions(ctx *fiber.Ctx) error {
|
||||
|
||||
err := c.be.RemoveTags(ctx.Context(), bucket, key)
|
||||
return SendResponse(ctx, err, &MetaOpts{
|
||||
Status: http.StatusNoContent,
|
||||
Logger: c.logger,
|
||||
EvSender: c.evSender,
|
||||
Action: "RemoveObjectTagging",
|
||||
@@ -957,6 +958,7 @@ type MetaOpts struct {
|
||||
EventName s3event.EventType
|
||||
ObjectETag *string
|
||||
VersionId *string
|
||||
Status int
|
||||
}
|
||||
|
||||
func SendResponse(ctx *fiber.Ctx, err error, l *MetaOpts) error {
|
||||
@@ -991,9 +993,12 @@ func SendResponse(ctx *fiber.Ctx, err error, l *MetaOpts) error {
|
||||
|
||||
utils.LogCtxDetails(ctx, []byte{})
|
||||
|
||||
if l.Status == 0 {
|
||||
l.Status = http.StatusOK
|
||||
}
|
||||
// https://github.com/gofiber/fiber/issues/2080
|
||||
// ctx.SendStatus() sets incorrect content length on HEAD request
|
||||
ctx.Status(http.StatusOK)
|
||||
ctx.Status(l.Status)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -1065,7 +1065,7 @@ func TestS3ApiController_DeleteActions(t *testing.T) {
|
||||
req: httptest.NewRequest(http.MethodDelete, "/my-bucket/my-key/key2?tagging", nil),
|
||||
},
|
||||
wantErr: false,
|
||||
statusCode: 200,
|
||||
statusCode: 204,
|
||||
},
|
||||
{
|
||||
name: "Delete-object-success",
|
||||
@@ -1493,6 +1493,7 @@ func Test_response(t *testing.T) {
|
||||
ctx *fiber.Ctx
|
||||
resp any
|
||||
err error
|
||||
opts *MetaOpts
|
||||
}
|
||||
|
||||
app := fiber.New()
|
||||
@@ -1510,6 +1511,7 @@ func Test_response(t *testing.T) {
|
||||
ctx: ctx,
|
||||
resp: nil,
|
||||
err: s3err.GetAPIError(s3err.ErrInternalError),
|
||||
opts: &MetaOpts{},
|
||||
},
|
||||
wantErr: false,
|
||||
statusCode: 500,
|
||||
@@ -1520,6 +1522,7 @@ func Test_response(t *testing.T) {
|
||||
ctx: ctx,
|
||||
resp: nil,
|
||||
err: fmt.Errorf("custom error"),
|
||||
opts: &MetaOpts{},
|
||||
},
|
||||
wantErr: false,
|
||||
statusCode: 500,
|
||||
@@ -1530,6 +1533,7 @@ func Test_response(t *testing.T) {
|
||||
ctx: ctx,
|
||||
resp: nil,
|
||||
err: s3err.GetAPIError(s3err.ErrNotImplemented),
|
||||
opts: &MetaOpts{},
|
||||
},
|
||||
wantErr: false,
|
||||
statusCode: 501,
|
||||
@@ -1540,14 +1544,28 @@ func Test_response(t *testing.T) {
|
||||
ctx: ctx,
|
||||
resp: "Valid response",
|
||||
err: nil,
|
||||
opts: &MetaOpts{},
|
||||
},
|
||||
wantErr: false,
|
||||
statusCode: 200,
|
||||
},
|
||||
{
|
||||
name: "Successful-response-status-204",
|
||||
args: args{
|
||||
ctx: ctx,
|
||||
resp: "Valid response",
|
||||
err: nil,
|
||||
opts: &MetaOpts{
|
||||
Status: 204,
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
statusCode: 204,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if err := SendResponse(tt.args.ctx, tt.args.err, &MetaOpts{}); (err != nil) != tt.wantErr {
|
||||
if err := SendResponse(tt.args.ctx, tt.args.err, tt.args.opts); (err != nil) != tt.wantErr {
|
||||
t.Errorf("response() %v error = %v, wantErr %v", tt.name, err, tt.wantErr)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user