From e554fee7bff6eac7b6671b2ad2ac56bd7aebc946 Mon Sep 17 00:00:00 2001 From: TheoryOfNekomata Date: Wed, 17 Apr 2024 12:58:42 +0800 Subject: [PATCH] Fix Accept-Patch in OPTIONS Use resource allowed patches in OPTIONS. --- packages/core/src/backend/servers/http/core.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/core/src/backend/servers/http/core.ts b/packages/core/src/backend/servers/http/core.ts index 68bac98..3c2f696 100644 --- a/packages/core/src/backend/servers/http/core.ts +++ b/packages/core/src/backend/servers/http/core.ts @@ -551,15 +551,10 @@ export const createServer = (backendState: BackendState, serverParams = {} as Cr if (resourceReq.method === 'POST') { headers['Accept-Post'] = Array.from(resourceReq.backend.app.mediaTypes.keys()).join(','); } else if (resourceReq.method === 'PATCH') { - headers['Accept-Patch'] = Array.from(resourceReq.backend.app.mediaTypes.keys()).map((m) => { - const [mimeType, mimeSubtype] = m.split('/'); - - // TODO accept only patch document type from request - // TODO implement Vary header (which headers influenced the request) - // TODO implement OPTIONS method for determining the accepted media types and languages - // TODO configure strict and lax accept behavior for content negotiation - return `${mimeType}/merge-patch+${mimeSubtype}`; - }).join(','); + headers['Accept-Patch'] = Array.from(Object.entries(PATCH_CONTENT_MAP_TYPE)) + .filter(([, value]) => Object.keys(resourceReq.resource.state.canPatch).includes(value)) + .map(([contentType]) => contentType) + .join(','); } handleError(new ErrorPlainResponse('unableToSerializeResponse', {