Skip to content

Commit

Permalink
fixup: conditions in routesPOST
Browse files Browse the repository at this point in the history
  • Loading branch information
KazToozs committed Jul 18, 2024
1 parent 9e824e2 commit 1f44698
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions lib/s3routes/routes/routePOST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,21 @@ export default function routePOST(
corsHeaders));
}

if (objectKey === undefined) {
if (Object.keys(query).length > 0) {
return routesUtils.responseNoBody(errors.InvalidArgument
.customizeDescription("Query String Parameters not allowed on POST requests."), null,
response, 400, log);
// Handle objectKey and query string conditions
if (objectKey !== undefined) {
if (Object.keys(query).length === 0) {
return api.callPostObject('objectPost', request, response, log, (err, resHeaders) =>
routesUtils.responseNoBody(err, resHeaders, response, 204, log));
} else {
// If there's an objectKey and a query string but no match with the previous conditions
return routesUtils.responseNoBody(errors.MethodNotAllowed, null, response, 405, log);
}
return api.callPostObject('objectPost', request, response, log, (err, resHeaders) => routesUtils.responseNoBody(err, resHeaders, response, 204, log));
}

// Handle invalid query string parameters
if (Object.keys(query).length > 0) {
return routesUtils.responseNoBody(errors.InvalidArgument
.customizeDescription("Query String Parameters not allowed on POST requests."), null, response, 400, log);
}

return routesUtils.responseNoBody(errors.NotImplemented, null, response,
Expand Down

0 comments on commit 1f44698

Please sign in to comment.