Skip to content

Commit

Permalink
Better Accept header support
Browse files Browse the repository at this point in the history
  • Loading branch information
awlayton committed Jun 22, 2021
1 parent 767bf68 commit ffbc562
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions oada/services/http-handler/src/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ const plugin: FastifyPluginAsync<Options> = 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(
Expand All @@ -268,9 +268,11 @@ const plugin: FastifyPluginAsync<Options> = 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:
Expand Down

0 comments on commit ffbc562

Please sign in to comment.