From d62ee372c5dd56cc35f20954771f95921b611715 Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Fri, 5 Apr 2024 12:47:13 +0900 Subject: [PATCH 1/3] Version bump [ci skip] --- CHANGES.md | 6 ++++++ deno.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 11d2f6ce..54e40ca3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,12 @@ nav_order: 9 Fedify changelog ================ +Version 0.5.1 +------------- + +To be released. + + Version 0.5.0 ------------- diff --git a/deno.json b/deno.json index f19776db..287091d9 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@fedify/fedify", - "version": "0.5.0", + "version": "0.5.1", "exports": { ".": "./mod.ts", "./federation": "./federation/mod.ts", From 7dcf4b2b80a899d3ae29dd3c9945cbff3062df74 Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Fri, 5 Apr 2024 13:09:51 +0900 Subject: [PATCH 2/3] Negotiate after determining if the resource exists Fix https://github.com/dahlia/fedify/issues/34 --- CHANGES.md | 8 ++++++++ federation/handler.test.ts | 30 ++++++++++++++++++++++++++++++ federation/handler.ts | 16 ++++++++-------- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 54e40ca3..4bf2a7e7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,14 @@ Version 0.5.1 To be released. + - Fixed a bug of `Federation` that its actor/collection dispatchers had done + content negotiation before determining if the resource exists or not. + It also fixed a bug that `integrateHandler()` from `@fedify/fedify/x/fresh` + had responded with `406 Not Acceptable` instead of `404 Not Found` when + the resource does not exist in the web browser. [[#34]] + +[#34]: https://github.com/dahlia/fedify/issues/34 + Version 0.5.0 ------------- diff --git a/federation/handler.test.ts b/federation/handler.test.ts index b1fe4d71..10d244cf 100644 --- a/federation/handler.test.ts +++ b/federation/handler.test.ts @@ -100,6 +100,21 @@ Deno.test("handleActor()", async () => { assertEquals(onNotAcceptableCalled, context.request); onNotAcceptableCalled = null; + response = await handleActor( + context.request, + { + context, + handle: "no-one", + actorDispatcher, + onNotFound, + onNotAcceptable, + }, + ); + assertEquals(response.status, 404); + assertEquals(onNotFoundCalled, context.request); + assertEquals(onNotAcceptableCalled, null); + + onNotFoundCalled = null; context = createRequestContext({ ...context, request: new Request(context.url, { @@ -235,6 +250,21 @@ Deno.test("handleCollection()", async () => { assertEquals(onNotAcceptableCalled, context.request); onNotAcceptableCalled = null; + response = await handleCollection( + context.request, + { + context, + handle: "no-one", + collectionCallbacks: { dispatcher }, + onNotFound, + onNotAcceptable, + }, + ); + assertEquals(response.status, 404); + assertEquals(onNotFoundCalled, context.request); + assertEquals(onNotAcceptableCalled, null); + + onNotFoundCalled = null; context = createRequestContext({ ...context, request: new Request(context.url, { diff --git a/federation/handler.ts b/federation/handler.ts index 686e556e..d674634b 100644 --- a/federation/handler.ts +++ b/federation/handler.ts @@ -53,16 +53,16 @@ export async function handleActor( const response = onNotFound(request); return response instanceof Promise ? await response : response; } - if (!acceptsJsonLd(request)) { - const response = onNotAcceptable(request); - return response instanceof Promise ? await response : response; - } const key = await context.getActorKey(handle); const actor = await actorDispatcher(context, handle, key); if (actor == null) { const response = onNotFound(request); return response instanceof Promise ? await response : response; } + if (!acceptsJsonLd(request)) { + const response = onNotAcceptable(request); + return response instanceof Promise ? await response : response; + } const jsonLd = await actor.toJsonLd(context); return new Response(JSON.stringify(jsonLd), { headers: { @@ -122,10 +122,6 @@ export async function handleCollection< const response = onNotFound(request); return response instanceof Promise ? await response : response; } - if (!acceptsJsonLd(request)) { - const response = onNotAcceptable(request); - return response instanceof Promise ? await response : response; - } const url = new URL(request.url); const cursor = url.searchParams.get("cursor"); let collection: OrderedCollection | OrderedCollectionPage; @@ -200,6 +196,10 @@ export async function handleCollection< partOf.searchParams.delete("cursor"); collection = new OrderedCollectionPage({ prev, next, items, partOf }); } + if (!acceptsJsonLd(request)) { + const response = onNotAcceptable(request); + return response instanceof Promise ? await response : response; + } const jsonLd = await collection.toJsonLd(context); return new Response(JSON.stringify(jsonLd), { headers: { From 24728173842a2167605d09f2cd13d8aafcc8c39c Mon Sep 17 00:00:00 2001 From: Hong Minhee Date: Fri, 5 Apr 2024 13:16:20 +0900 Subject: [PATCH 3/3] Release 0.5.1 --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 4bf2a7e7..9b7ac205 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,7 +11,7 @@ Fedify changelog Version 0.5.1 ------------- -To be released. +Released on April 5, 2024. - Fixed a bug of `Federation` that its actor/collection dispatchers had done content negotiation before determining if the resource exists or not.