Loading CHANGES.md +16 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,11 @@ Version 1.0.8 To be released. - Fixed a bug where default document loaders had thrown a `TypeError` with a message <q>Body is unusable: Body has already been read</q> or <q>Body already consumed</q> when the content type of the response was an HTML document and there's no link to a JSON-LD document. Version 1.0.7 ------------- Loading Loading @@ -258,6 +263,17 @@ Released on September 26, 2024. [#137]: https://github.com/dahlia/fedify/issues/137 Version 0.15.6 -------------- Released on November 12, 2024. - Fixed a bug where default document loaders had thrown a `TypeError` with a message <q>Body is unusable: Body has already been read</q> or <q>Body already consumed</q> when the content type of the response was an HTML document and there's no link to a JSON-LD document. Version 0.15.5 -------------- Loading src/runtime/docloader.test.ts +27 −0 Original line number Diff line number Diff line Loading @@ -207,6 +207,33 @@ test("fetchDocumentLoader()", async (t) => { }); }); mf.mock("GET@/wrong-content-type", (_req) => new Response( JSON.stringify({ "@context": "https://www.w3.org/ns/activitystreams", id: "https://example.com/wrong-content-type", name: "Fetched object", type: "Object", }), { status: 200, headers: { "Content-Type": "text/html; charset=utf-8" } }, )); await t.step("Wrong Content-Type", async () => { assertEquals( await fetchDocumentLoader("https://example.com/wrong-content-type"), { contextUrl: null, documentUrl: "https://example.com/wrong-content-type", document: { "@context": "https://www.w3.org/ns/activitystreams", id: "https://example.com/wrong-content-type", name: "Fetched object", type: "Object", }, }, ); }); mf.mock("GET@/404", (_req) => new Response("", { status: 404 })); await t.step("not ok", async () => { Loading src/runtime/docloader.ts +5 −5 Original line number Diff line number Diff line Loading @@ -150,6 +150,7 @@ async function getRemoteDocument( } } } let document: unknown; if ( !jsonLd && (contentType === "text/html" || contentType?.startsWith("text/html;") || Loading Loading @@ -185,6 +186,9 @@ async function getRemoteDocument( return await fetch(new URL(attribs.href, docUrl).href); } } document = JSON.parse(html); } else { document = await response.json(); } logger.debug( "Fetched document: {status} {url} {headers}", Loading @@ -194,11 +198,7 @@ async function getRemoteDocument( headers: Object.fromEntries(response.headers.entries()), }, ); return { contextUrl, document: await response.json(), documentUrl, }; return { contextUrl, document, documentUrl }; } /** Loading Loading
CHANGES.md +16 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,11 @@ Version 1.0.8 To be released. - Fixed a bug where default document loaders had thrown a `TypeError` with a message <q>Body is unusable: Body has already been read</q> or <q>Body already consumed</q> when the content type of the response was an HTML document and there's no link to a JSON-LD document. Version 1.0.7 ------------- Loading Loading @@ -258,6 +263,17 @@ Released on September 26, 2024. [#137]: https://github.com/dahlia/fedify/issues/137 Version 0.15.6 -------------- Released on November 12, 2024. - Fixed a bug where default document loaders had thrown a `TypeError` with a message <q>Body is unusable: Body has already been read</q> or <q>Body already consumed</q> when the content type of the response was an HTML document and there's no link to a JSON-LD document. Version 0.15.5 -------------- Loading
src/runtime/docloader.test.ts +27 −0 Original line number Diff line number Diff line Loading @@ -207,6 +207,33 @@ test("fetchDocumentLoader()", async (t) => { }); }); mf.mock("GET@/wrong-content-type", (_req) => new Response( JSON.stringify({ "@context": "https://www.w3.org/ns/activitystreams", id: "https://example.com/wrong-content-type", name: "Fetched object", type: "Object", }), { status: 200, headers: { "Content-Type": "text/html; charset=utf-8" } }, )); await t.step("Wrong Content-Type", async () => { assertEquals( await fetchDocumentLoader("https://example.com/wrong-content-type"), { contextUrl: null, documentUrl: "https://example.com/wrong-content-type", document: { "@context": "https://www.w3.org/ns/activitystreams", id: "https://example.com/wrong-content-type", name: "Fetched object", type: "Object", }, }, ); }); mf.mock("GET@/404", (_req) => new Response("", { status: 404 })); await t.step("not ok", async () => { Loading
src/runtime/docloader.ts +5 −5 Original line number Diff line number Diff line Loading @@ -150,6 +150,7 @@ async function getRemoteDocument( } } } let document: unknown; if ( !jsonLd && (contentType === "text/html" || contentType?.startsWith("text/html;") || Loading Loading @@ -185,6 +186,9 @@ async function getRemoteDocument( return await fetch(new URL(attribs.href, docUrl).href); } } document = JSON.parse(html); } else { document = await response.json(); } logger.debug( "Fetched document: {status} {url} {headers}", Loading @@ -194,11 +198,7 @@ async function getRemoteDocument( headers: Object.fromEntries(response.headers.entries()), }, ); return { contextUrl, document: await response.json(), documentUrl, }; return { contextUrl, document, documentUrl }; } /** Loading