Loading CHANGES.md +2 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ To be released. - Added `integrateHandler()` function. - Added `integrateHandlerOptions()` function. - Now `loookupWebFinger()` follows redirections. [Fresh]: https://fresh.deno.dev/ Loading webfinger/lookup.test.ts +13 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,19 @@ Deno.test("lookupWebFinger()", async (t) => { assertEquals(await lookupWebFinger("acct:johndoe@example.com"), null); }); mf.mock( "GET@/.well-known/webfinger", (req) => Response.redirect(new URL("/.well-known/webfinger2", req.url)), ); mf.mock( "GET@/.well-known/webfinger2", (_) => new Response(JSON.stringify(expected)), ); await t.step("redirection", async () => { assertEquals(await lookupWebFinger("acct:johndoe@example.com"), expected); }); mf.uninstall(); }); Loading webfinger/lookup.ts +20 −12 Original line number Diff line number Diff line Loading @@ -18,13 +18,20 @@ export async function lookupWebFinger( } else { server = resource.hostname; } const url = new URL(`https://${server}/.well-known/webfinger`); let url = new URL(`https://${server}/.well-known/webfinger`); url.searchParams.set("resource", resource.href); while (true) { const response = await fetch(url, { headers: { Accept: "application/jrd+json", }, headers: { Accept: "application/jrd+json" }, redirect: "manual", }); if ( response.status >= 300 && response.status < 400 && response.headers.has("Location") ) { url = new URL(response.headers.get("Location")!); continue; } if (!response.ok) return null; try { return await response.json(); Loading @@ -33,3 +40,4 @@ export async function lookupWebFinger( throw e; } } } Loading
CHANGES.md +2 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ To be released. - Added `integrateHandler()` function. - Added `integrateHandlerOptions()` function. - Now `loookupWebFinger()` follows redirections. [Fresh]: https://fresh.deno.dev/ Loading
webfinger/lookup.test.ts +13 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,19 @@ Deno.test("lookupWebFinger()", async (t) => { assertEquals(await lookupWebFinger("acct:johndoe@example.com"), null); }); mf.mock( "GET@/.well-known/webfinger", (req) => Response.redirect(new URL("/.well-known/webfinger2", req.url)), ); mf.mock( "GET@/.well-known/webfinger2", (_) => new Response(JSON.stringify(expected)), ); await t.step("redirection", async () => { assertEquals(await lookupWebFinger("acct:johndoe@example.com"), expected); }); mf.uninstall(); }); Loading
webfinger/lookup.ts +20 −12 Original line number Diff line number Diff line Loading @@ -18,13 +18,20 @@ export async function lookupWebFinger( } else { server = resource.hostname; } const url = new URL(`https://${server}/.well-known/webfinger`); let url = new URL(`https://${server}/.well-known/webfinger`); url.searchParams.set("resource", resource.href); while (true) { const response = await fetch(url, { headers: { Accept: "application/jrd+json", }, headers: { Accept: "application/jrd+json" }, redirect: "manual", }); if ( response.status >= 300 && response.status < 400 && response.headers.has("Location") ) { url = new URL(response.headers.get("Location")!); continue; } if (!response.ok) return null; try { return await response.json(); Loading @@ -33,3 +40,4 @@ export async function lookupWebFinger( throw e; } } }