From 310c4353425c5f64f18a421717d525ed5a2c5dab Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Thu, 8 Jun 2023 08:11:50 -0500 Subject: [PATCH] Add an Accept header for manifests Our IIIF server provides v2 APIs by default, but if the client provides an Accept header with the v3 profile, it will provide a v3 response. This triggers that behavior. --- src/state/sagas/iiif.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/state/sagas/iiif.js b/src/state/sagas/iiif.js index 3a613ee934..afefad349a 100644 --- a/src/state/sagas/iiif.js +++ b/src/state/sagas/iiif.js @@ -105,13 +105,24 @@ function* fetchIiifResourceWithAuth(url, iiifResource, options, { degraded, fail yield put((degraded || success)({ json, response, tokenServiceId })); } +// Prefer v3 API response, but v2 is acceptable or even any JSON+LD or JSON. +const MANIFEST_ACCEPT_HEADER = 'application/ld+json;q=0.9;profile="http://iiif.io/api/presentation/3/context.json", ' + + 'application/ld+json;q=0.7;profile="http://iiif.io/api/presentation/2/context.json", ' + + 'application/ls+json;q=0.5, ' + + 'application/json;q=0.2'; + /** */ export function* fetchManifest({ manifestId }) { const callbacks = { failure: ({ error, json, response }) => receiveManifestFailure(manifestId, typeof error === 'object' ? String(error) : error), success: ({ json, response }) => receiveManifest(manifestId, json), }; - const dispatch = yield call(fetchIiifResource, manifestId, {}, callbacks); + const dispatch = yield call( + fetchIiifResource, + manifestId, + { headers: { Accept: MANIFEST_ACCEPT_HEADER } }, + callbacks, + ); yield put(dispatch); }