From ffbc562a272cb0029c7beb42c24706ad92101172 Mon Sep 17 00:00:00 2001 From: Alex Layton Date: Tue, 22 Jun 2021 13:58:17 -0400 Subject: [PATCH] Better Accept header support --- oada/services/http-handler/src/resources.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/oada/services/http-handler/src/resources.ts b/oada/services/http-handler/src/resources.ts index bdbdd833..19377880 100644 --- a/oada/services/http-handler/src/resources.ts +++ b/oada/services/http-handler/src/resources.ts @@ -245,7 +245,7 @@ const plugin: FastifyPluginAsync = async function (fastify, opts) { // results. I think we can do that in one arango query if ( - typeis.is(oadaGraph.type!, ['json', '+json']) || + typeis.is(type, ['json', '+json']) || oadaGraph['path_leftover'].match(/\/_meta$/) ) { const doc = await resources.getResource( @@ -268,9 +268,11 @@ const plugin: FastifyPluginAsync = async function (fastify, opts) { const res = unflattenMeta(doc); + // TODO: Support non-JSON accept? (e.g., YAML) const accept = request.accepts(); - switch (accept.type(['json'])) { + switch (accept.type(['json', type])) { case 'json': + case type: // TODO: Better way to ensure string gets JSON serialized? return reply.serializer(JSON.stringify).send(res); default: