Skip to content

Commit 481c9d7

Browse files
author
Andrea Cosentino
committed
fix: get/head and delete fs requests handling
1 parent 92efd23 commit 481c9d7

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/utils/plugin.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,15 @@ async function handlingApiFsRequest(logger: ILogger, fullUrl: URL, request: Univ
186186
logger.debug("handlingApiFsRequest: parsing request");
187187
await Utils.request.parseRequest(request, res, fullUrl, parser, logger);
188188
}
189-
if (request.body !== null || request.files !== null) {
189+
if (request.files !== null) {
190190
throw new UniversalApiError(`${request.method} request cannot have a body in ${IS_API_REST_FS ? "REST " : ""}File System API mode`, "ERROR", fullUrl.pathname, Constants.HTTP_STATUS_CODE.BAD_REQUEST);
191191
}
192+
if (request.body !== null) {
193+
const cleanBody = Utils.request.getCleanBody(request.method, request.body, paginationHandler, filtersHandler, paginationPlugin, filtersPlugin);
194+
if (cleanBody !== null) {
195+
throw new UniversalApiError(`${request.method} request cannot have a body in ${IS_API_REST_FS ? "REST " : ""}File System API mode`, "ERROR", fullUrl.pathname, Constants.HTTP_STATUS_CODE.BAD_REQUEST);
196+
}
197+
}
192198
try {
193199
logger.debug("handlingApiFsRequest: applying pagination and filters");
194200
Utils.request.applyPaginationAndFilters(request, paginationHandler, filtersHandler, paginationPlugin, filtersPlugin, dataFile);
@@ -391,9 +397,15 @@ async function handlingApiFsRequest(logger: ILogger, fullUrl: URL, request: Univ
391397
logger.debug("handlingApiFsRequest: parsing request");
392398
await Utils.request.parseRequest(request, res, fullUrl, parser, logger);
393399
}
394-
if (request.body !== null || request.files !== null) {
400+
if (request.files !== null) {
395401
throw new UniversalApiError(`DELETE request cannot have a body in ${IS_API_REST_FS ? "REST " : ""}File System API mode`, "ERROR", fullUrl.pathname, Constants.HTTP_STATUS_CODE.BAD_REQUEST);
396402
}
403+
if (request.body !== null) {
404+
const cleanBody = Utils.request.getCleanBody(request.method, request.body, paginationHandler, filtersHandler, paginationPlugin, filtersPlugin);
405+
if (cleanBody !== null) {
406+
throw new UniversalApiError(`DELETE request cannot have a body in ${IS_API_REST_FS ? "REST " : ""}File System API mode`, "ERROR", fullUrl.pathname, Constants.HTTP_STATUS_CODE.BAD_REQUEST);
407+
}
408+
}
397409
result.status = Constants.HTTP_STATUS_CODE.NO_CONTENT;
398410
try {
399411
let removeFile = true;

0 commit comments

Comments
 (0)