From 70dfb6c20f9b28d21279723dbf86ef701dde7449 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Mon, 25 Mar 2024 13:06:35 -0400 Subject: [PATCH] DOI Content Negotiation: Use Content-Type header instead of sniffing --- DOI Content Negotiation.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/DOI Content Negotiation.js b/DOI Content Negotiation.js index fa4e9a090b8..01a8abb2542 100644 --- a/DOI Content Negotiation.js +++ b/DOI Content Negotiation.js @@ -8,7 +8,7 @@ "priority": 100, "inRepository": true, "translatorType": 8, - "lastUpdated": "2023-09-22 09:54:11" + "lastUpdated": "2024-03-25 16:57:39" } /* @@ -64,18 +64,20 @@ async function doSearch(items) { } async function processDOI(doi) { - let response = await requestText( + let response = await request( `https://doi.org/${encodeURIComponent(doi)}`, { headers: { Accept: "application/vnd.datacite.datacite+json, application/vnd.crossref.unixref+xml, application/vnd.citationstyles.csl+json" } } ); + let { headers, body } = response; // by content negotiation we asked for datacite or crossref format, or CSL JSON - if (!response) return; - Z.debug(response); + if (!body) return; + Z.debug(body); let trans = Zotero.loadTranslator('import'); - trans.setString(response); + trans.setString(body); - if (response.includes("