@fedify/hono 2.3.12 → 2.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mod.cjs +55 -9
- package/dist/mod.js +55 -9
- package/package.json +6 -4
package/dist/mod.cjs
CHANGED
|
@@ -29,15 +29,61 @@ function integrateFetchOptions(ctx, next) {
|
|
|
29
29
|
return ctx.res;
|
|
30
30
|
},
|
|
31
31
|
async onNotAcceptable(_req) {
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
const { matchedRoutes, routeIndex } = ctx.req;
|
|
33
|
+
if (matchedRoutes == null || routeIndex == null || matchedRoutes.length > routeIndex + 1 || matchedRoutes.some((route) => route.method !== "ALL" || !route.path.endsWith("*"))) {
|
|
34
|
+
await next();
|
|
35
|
+
return ctx.res;
|
|
36
|
+
}
|
|
37
|
+
const context = ctx;
|
|
38
|
+
const text = context.text;
|
|
39
|
+
const ownRes = Object.getOwnPropertyDescriptor(ctx, "res");
|
|
40
|
+
let owner = ctx;
|
|
41
|
+
let res = ownRes;
|
|
42
|
+
while (res == null && (owner = Object.getPrototypeOf(owner)) != null) res = Object.getOwnPropertyDescriptor(owner, "res");
|
|
43
|
+
let defaultResponse;
|
|
44
|
+
let defaultNotFound = false;
|
|
45
|
+
const wrappedText = (...args) => {
|
|
46
|
+
const response = text.apply(ctx, args);
|
|
47
|
+
if (args[0] === "404 Not Found" && args[1] === 404) defaultResponse = response;
|
|
48
|
+
return response;
|
|
49
|
+
};
|
|
50
|
+
const setRes = (response) => {
|
|
51
|
+
res.set.call(ctx, response);
|
|
52
|
+
defaultNotFound = response === defaultResponse;
|
|
53
|
+
};
|
|
54
|
+
if (res?.get != null && res.set != null && ownRes?.configurable !== false && text != null) {
|
|
55
|
+
context.text = wrappedText;
|
|
56
|
+
Object.defineProperty(ctx, "res", {
|
|
57
|
+
configurable: true,
|
|
58
|
+
enumerable: res.enumerable,
|
|
59
|
+
get: () => res.get.call(ctx),
|
|
60
|
+
set: setRes
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
await next();
|
|
65
|
+
} finally {
|
|
66
|
+
if (context.text === wrappedText) context.text = text;
|
|
67
|
+
if (Object.getOwnPropertyDescriptor(ctx, "res")?.set === setRes) if (ownRes == null) delete ctx.res;
|
|
68
|
+
else Object.defineProperty(ctx, "res", ownRes);
|
|
69
|
+
}
|
|
70
|
+
if (ctx.res.status !== 404 || !defaultNotFound) return ctx.res;
|
|
71
|
+
const vary = ctx.res.headers.get("Vary");
|
|
72
|
+
ctx.res = new Response("Not acceptable", { status: 406 });
|
|
73
|
+
for (const header of [
|
|
74
|
+
"Content-Encoding",
|
|
75
|
+
"Content-Language",
|
|
76
|
+
"Content-Range",
|
|
77
|
+
"ETag",
|
|
78
|
+
"Last-Modified",
|
|
79
|
+
"Transfer-Encoding",
|
|
80
|
+
"Content-Length"
|
|
81
|
+
]) ctx.res.headers.delete(header);
|
|
82
|
+
ctx.res.headers.set("Content-Type", "text/plain; charset=utf-8");
|
|
83
|
+
const fields = vary?.split(",").map((field) => field.trim()) ?? [];
|
|
84
|
+
if (!fields.some((field) => field === "*" || field.toLowerCase() === "accept")) fields.push("Accept");
|
|
85
|
+
ctx.res.headers.set("Vary", fields.join(", "));
|
|
86
|
+
return ctx.res;
|
|
41
87
|
}
|
|
42
88
|
};
|
|
43
89
|
}
|
package/dist/mod.js
CHANGED
|
@@ -28,15 +28,61 @@ function integrateFetchOptions(ctx, next) {
|
|
|
28
28
|
return ctx.res;
|
|
29
29
|
},
|
|
30
30
|
async onNotAcceptable(_req) {
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
const { matchedRoutes, routeIndex } = ctx.req;
|
|
32
|
+
if (matchedRoutes == null || routeIndex == null || matchedRoutes.length > routeIndex + 1 || matchedRoutes.some((route) => route.method !== "ALL" || !route.path.endsWith("*"))) {
|
|
33
|
+
await next();
|
|
34
|
+
return ctx.res;
|
|
35
|
+
}
|
|
36
|
+
const context = ctx;
|
|
37
|
+
const text = context.text;
|
|
38
|
+
const ownRes = Object.getOwnPropertyDescriptor(ctx, "res");
|
|
39
|
+
let owner = ctx;
|
|
40
|
+
let res = ownRes;
|
|
41
|
+
while (res == null && (owner = Object.getPrototypeOf(owner)) != null) res = Object.getOwnPropertyDescriptor(owner, "res");
|
|
42
|
+
let defaultResponse;
|
|
43
|
+
let defaultNotFound = false;
|
|
44
|
+
const wrappedText = (...args) => {
|
|
45
|
+
const response = text.apply(ctx, args);
|
|
46
|
+
if (args[0] === "404 Not Found" && args[1] === 404) defaultResponse = response;
|
|
47
|
+
return response;
|
|
48
|
+
};
|
|
49
|
+
const setRes = (response) => {
|
|
50
|
+
res.set.call(ctx, response);
|
|
51
|
+
defaultNotFound = response === defaultResponse;
|
|
52
|
+
};
|
|
53
|
+
if (res?.get != null && res.set != null && ownRes?.configurable !== false && text != null) {
|
|
54
|
+
context.text = wrappedText;
|
|
55
|
+
Object.defineProperty(ctx, "res", {
|
|
56
|
+
configurable: true,
|
|
57
|
+
enumerable: res.enumerable,
|
|
58
|
+
get: () => res.get.call(ctx),
|
|
59
|
+
set: setRes
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
await next();
|
|
64
|
+
} finally {
|
|
65
|
+
if (context.text === wrappedText) context.text = text;
|
|
66
|
+
if (Object.getOwnPropertyDescriptor(ctx, "res")?.set === setRes) if (ownRes == null) delete ctx.res;
|
|
67
|
+
else Object.defineProperty(ctx, "res", ownRes);
|
|
68
|
+
}
|
|
69
|
+
if (ctx.res.status !== 404 || !defaultNotFound) return ctx.res;
|
|
70
|
+
const vary = ctx.res.headers.get("Vary");
|
|
71
|
+
ctx.res = new Response("Not acceptable", { status: 406 });
|
|
72
|
+
for (const header of [
|
|
73
|
+
"Content-Encoding",
|
|
74
|
+
"Content-Language",
|
|
75
|
+
"Content-Range",
|
|
76
|
+
"ETag",
|
|
77
|
+
"Last-Modified",
|
|
78
|
+
"Transfer-Encoding",
|
|
79
|
+
"Content-Length"
|
|
80
|
+
]) ctx.res.headers.delete(header);
|
|
81
|
+
ctx.res.headers.set("Content-Type", "text/plain; charset=utf-8");
|
|
82
|
+
const fields = vary?.split(",").map((field) => field.trim()) ?? [];
|
|
83
|
+
if (!fields.some((field) => field === "*" || field.toLowerCase() === "accept")) fields.push("Accept");
|
|
84
|
+
ctx.res.headers.set("Vary", fields.join(", "));
|
|
85
|
+
return ctx.res;
|
|
40
86
|
}
|
|
41
87
|
};
|
|
42
88
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/hono",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.13",
|
|
4
4
|
"description": "Integrate Fedify with Hono",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Fedify",
|
|
@@ -50,16 +50,18 @@
|
|
|
50
50
|
],
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"hono": "^4.0.0",
|
|
53
|
-
"@fedify/fedify": "^2.3.
|
|
53
|
+
"@fedify/fedify": "^2.3.13"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"tsdown": "^0.22.0",
|
|
57
|
-
"typescript": "^6.0.0"
|
|
57
|
+
"typescript": "^6.0.0",
|
|
58
|
+
"@fedify/fixture": "2.0.0"
|
|
58
59
|
},
|
|
59
60
|
"scripts": {
|
|
60
61
|
"build:self": "tsdown",
|
|
61
62
|
"build": "pnpm --filter @fedify/hono... run build:self",
|
|
62
63
|
"prepublish": "pnpm build",
|
|
63
|
-
"test": "node --experimental-transform-types --test"
|
|
64
|
+
"test": "node --experimental-transform-types --test",
|
|
65
|
+
"test:bun": "bun test"
|
|
64
66
|
}
|
|
65
67
|
}
|