hono 4.7.5 → 4.7.7
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/cjs/client/client.js +8 -7
- package/dist/cjs/context.js +14 -22
- package/dist/cjs/helper/proxy/index.js +1 -1
- package/dist/cjs/middleware/compress/index.js +1 -1
- package/dist/cjs/middleware/trailing-slash/index.js +2 -2
- package/dist/client/client.js +8 -7
- package/dist/context.js +14 -22
- package/dist/helper/proxy/index.js +1 -1
- package/dist/middleware/compress/index.js +1 -1
- package/dist/middleware/trailing-slash/index.js +2 -2
- package/dist/types/context.d.ts +1 -1
- package/dist/types/middleware/basic-auth/index.d.ts +1 -1
- package/dist/types/middleware/bearer-auth/index.d.ts +1 -1
- package/dist/types/middleware/context-storage/index.d.ts +1 -1
- package/dist/types/middleware/etag/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -112,20 +112,21 @@ class ClientRequestImpl {
|
|
|
112
112
|
}
|
|
113
113
|
const hc = (baseUrl, options) => createProxy(function proxyCallback(opts) {
|
|
114
114
|
const parts = [...opts.path];
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
const lastParts = parts.slice(-3).reverse();
|
|
116
|
+
if (lastParts[0] === "toString") {
|
|
117
|
+
if (lastParts[1] === "name") {
|
|
118
|
+
return lastParts[2] || "";
|
|
118
119
|
}
|
|
119
120
|
return proxyCallback.toString();
|
|
120
121
|
}
|
|
121
|
-
if (
|
|
122
|
-
if (
|
|
123
|
-
return
|
|
122
|
+
if (lastParts[0] === "valueOf") {
|
|
123
|
+
if (lastParts[1] === "name") {
|
|
124
|
+
return lastParts[2] || "";
|
|
124
125
|
}
|
|
125
126
|
return proxyCallback;
|
|
126
127
|
}
|
|
127
128
|
let method = "";
|
|
128
|
-
if (/^\$/.test(
|
|
129
|
+
if (/^\$/.test(lastParts[0])) {
|
|
129
130
|
const last = parts.pop();
|
|
130
131
|
if (last) {
|
|
131
132
|
method = last.replace(/^\$/, "");
|
package/dist/cjs/context.js
CHANGED
|
@@ -84,30 +84,19 @@ class Context {
|
|
|
84
84
|
set res(_res) {
|
|
85
85
|
this.#isFresh = false;
|
|
86
86
|
if (this.#res && _res) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
if (k === "set-cookie") {
|
|
93
|
-
const cookies = this.#res.headers.getSetCookie();
|
|
94
|
-
_res.headers.delete("set-cookie");
|
|
95
|
-
for (const cookie of cookies) {
|
|
96
|
-
_res.headers.append("set-cookie", cookie);
|
|
97
|
-
}
|
|
98
|
-
} else {
|
|
99
|
-
_res.headers.set(k, v);
|
|
100
|
-
}
|
|
87
|
+
_res = new Response(_res.body, _res);
|
|
88
|
+
for (const [k, v] of this.#res.headers.entries()) {
|
|
89
|
+
if (k === "content-type") {
|
|
90
|
+
continue;
|
|
101
91
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
return;
|
|
92
|
+
if (k === "set-cookie") {
|
|
93
|
+
const cookies = this.#res.headers.getSetCookie();
|
|
94
|
+
_res.headers.delete("set-cookie");
|
|
95
|
+
for (const cookie of cookies) {
|
|
96
|
+
_res.headers.append("set-cookie", cookie);
|
|
97
|
+
}
|
|
109
98
|
} else {
|
|
110
|
-
|
|
99
|
+
_res.headers.set(k, v);
|
|
111
100
|
}
|
|
112
101
|
}
|
|
113
102
|
}
|
|
@@ -124,6 +113,9 @@ class Context {
|
|
|
124
113
|
this.#renderer = renderer;
|
|
125
114
|
};
|
|
126
115
|
header = (name, value, options) => {
|
|
116
|
+
if (this.finalized) {
|
|
117
|
+
this.#res = new Response(this.#res.body, this.#res);
|
|
118
|
+
}
|
|
127
119
|
if (value === void 0) {
|
|
128
120
|
if (this.#headers) {
|
|
129
121
|
this.#headers.delete(name);
|
|
@@ -62,7 +62,7 @@ const preprocessRequestInit = (requestInit) => {
|
|
|
62
62
|
return requestInit;
|
|
63
63
|
};
|
|
64
64
|
const proxy = async (input, proxyInit) => {
|
|
65
|
-
const { raw, ...requestInit } = proxyInit ?? {};
|
|
65
|
+
const { raw, ...requestInit } = proxyInit instanceof Request ? { raw: proxyInit } : proxyInit ?? {};
|
|
66
66
|
const req = new Request(input, {
|
|
67
67
|
...buildRequestInitFromRequest(raw),
|
|
68
68
|
...preprocessRequestInit(requestInit)
|
|
@@ -29,7 +29,7 @@ const compress = (options) => {
|
|
|
29
29
|
return async function compress2(ctx, next) {
|
|
30
30
|
await next();
|
|
31
31
|
const contentLength = ctx.res.headers.get("Content-Length");
|
|
32
|
-
if (ctx.res.headers.has("Content-Encoding") || ctx.req.method === "HEAD" || contentLength && Number(contentLength) < threshold || !shouldCompress(ctx.res) || !shouldTransform(ctx.res)) {
|
|
32
|
+
if (ctx.res.headers.has("Content-Encoding") || ctx.res.headers.has("Transfer-Encoding") || ctx.req.method === "HEAD" || contentLength && Number(contentLength) < threshold || !shouldCompress(ctx.res) || !shouldTransform(ctx.res)) {
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
35
|
const accepted = ctx.req.header("Accept-Encoding");
|
|
@@ -25,7 +25,7 @@ module.exports = __toCommonJS(trailing_slash_exports);
|
|
|
25
25
|
const trimTrailingSlash = () => {
|
|
26
26
|
return async function trimTrailingSlash2(c, next) {
|
|
27
27
|
await next();
|
|
28
|
-
if (c.res.status === 404 && c.req.method === "GET" && c.req.path !== "/" && c.req.path.at(-1) === "/") {
|
|
28
|
+
if (c.res.status === 404 && (c.req.method === "GET" || c.req.method === "HEAD") && c.req.path !== "/" && c.req.path.at(-1) === "/") {
|
|
29
29
|
const url = new URL(c.req.url);
|
|
30
30
|
url.pathname = url.pathname.substring(0, url.pathname.length - 1);
|
|
31
31
|
c.res = c.redirect(url.toString(), 301);
|
|
@@ -35,7 +35,7 @@ const trimTrailingSlash = () => {
|
|
|
35
35
|
const appendTrailingSlash = () => {
|
|
36
36
|
return async function appendTrailingSlash2(c, next) {
|
|
37
37
|
await next();
|
|
38
|
-
if (c.res.status === 404 && c.req.method === "GET" && c.req.path.at(-1) !== "/") {
|
|
38
|
+
if (c.res.status === 404 && (c.req.method === "GET" || c.req.method === "HEAD") && c.req.path.at(-1) !== "/") {
|
|
39
39
|
const url = new URL(c.req.url);
|
|
40
40
|
url.pathname += "/";
|
|
41
41
|
c.res = c.redirect(url.toString(), 301);
|
package/dist/client/client.js
CHANGED
|
@@ -97,20 +97,21 @@ var ClientRequestImpl = class {
|
|
|
97
97
|
};
|
|
98
98
|
var hc = (baseUrl, options) => createProxy(function proxyCallback(opts) {
|
|
99
99
|
const parts = [...opts.path];
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
const lastParts = parts.slice(-3).reverse();
|
|
101
|
+
if (lastParts[0] === "toString") {
|
|
102
|
+
if (lastParts[1] === "name") {
|
|
103
|
+
return lastParts[2] || "";
|
|
103
104
|
}
|
|
104
105
|
return proxyCallback.toString();
|
|
105
106
|
}
|
|
106
|
-
if (
|
|
107
|
-
if (
|
|
108
|
-
return
|
|
107
|
+
if (lastParts[0] === "valueOf") {
|
|
108
|
+
if (lastParts[1] === "name") {
|
|
109
|
+
return lastParts[2] || "";
|
|
109
110
|
}
|
|
110
111
|
return proxyCallback;
|
|
111
112
|
}
|
|
112
113
|
let method = "";
|
|
113
|
-
if (/^\$/.test(
|
|
114
|
+
if (/^\$/.test(lastParts[0])) {
|
|
114
115
|
const last = parts.pop();
|
|
115
116
|
if (last) {
|
|
116
117
|
method = last.replace(/^\$/, "");
|
package/dist/context.js
CHANGED
|
@@ -61,30 +61,19 @@ var Context = class {
|
|
|
61
61
|
set res(_res) {
|
|
62
62
|
this.#isFresh = false;
|
|
63
63
|
if (this.#res && _res) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
if (k === "set-cookie") {
|
|
70
|
-
const cookies = this.#res.headers.getSetCookie();
|
|
71
|
-
_res.headers.delete("set-cookie");
|
|
72
|
-
for (const cookie of cookies) {
|
|
73
|
-
_res.headers.append("set-cookie", cookie);
|
|
74
|
-
}
|
|
75
|
-
} else {
|
|
76
|
-
_res.headers.set(k, v);
|
|
77
|
-
}
|
|
64
|
+
_res = new Response(_res.body, _res);
|
|
65
|
+
for (const [k, v] of this.#res.headers.entries()) {
|
|
66
|
+
if (k === "content-type") {
|
|
67
|
+
continue;
|
|
78
68
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
return;
|
|
69
|
+
if (k === "set-cookie") {
|
|
70
|
+
const cookies = this.#res.headers.getSetCookie();
|
|
71
|
+
_res.headers.delete("set-cookie");
|
|
72
|
+
for (const cookie of cookies) {
|
|
73
|
+
_res.headers.append("set-cookie", cookie);
|
|
74
|
+
}
|
|
86
75
|
} else {
|
|
87
|
-
|
|
76
|
+
_res.headers.set(k, v);
|
|
88
77
|
}
|
|
89
78
|
}
|
|
90
79
|
}
|
|
@@ -101,6 +90,9 @@ var Context = class {
|
|
|
101
90
|
this.#renderer = renderer;
|
|
102
91
|
};
|
|
103
92
|
header = (name, value, options) => {
|
|
93
|
+
if (this.finalized) {
|
|
94
|
+
this.#res = new Response(this.#res.body, this.#res);
|
|
95
|
+
}
|
|
104
96
|
if (value === void 0) {
|
|
105
97
|
if (this.#headers) {
|
|
106
98
|
this.#headers.delete(name);
|
|
@@ -40,7 +40,7 @@ var preprocessRequestInit = (requestInit) => {
|
|
|
40
40
|
return requestInit;
|
|
41
41
|
};
|
|
42
42
|
var proxy = async (input, proxyInit) => {
|
|
43
|
-
const { raw, ...requestInit } = proxyInit ?? {};
|
|
43
|
+
const { raw, ...requestInit } = proxyInit instanceof Request ? { raw: proxyInit } : proxyInit ?? {};
|
|
44
44
|
const req = new Request(input, {
|
|
45
45
|
...buildRequestInitFromRequest(raw),
|
|
46
46
|
...preprocessRequestInit(requestInit)
|
|
@@ -7,7 +7,7 @@ var compress = (options) => {
|
|
|
7
7
|
return async function compress2(ctx, next) {
|
|
8
8
|
await next();
|
|
9
9
|
const contentLength = ctx.res.headers.get("Content-Length");
|
|
10
|
-
if (ctx.res.headers.has("Content-Encoding") || ctx.req.method === "HEAD" || contentLength && Number(contentLength) < threshold || !shouldCompress(ctx.res) || !shouldTransform(ctx.res)) {
|
|
10
|
+
if (ctx.res.headers.has("Content-Encoding") || ctx.res.headers.has("Transfer-Encoding") || ctx.req.method === "HEAD" || contentLength && Number(contentLength) < threshold || !shouldCompress(ctx.res) || !shouldTransform(ctx.res)) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
13
|
const accepted = ctx.req.header("Accept-Encoding");
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
var trimTrailingSlash = () => {
|
|
3
3
|
return async function trimTrailingSlash2(c, next) {
|
|
4
4
|
await next();
|
|
5
|
-
if (c.res.status === 404 && c.req.method === "GET" && c.req.path !== "/" && c.req.path.at(-1) === "/") {
|
|
5
|
+
if (c.res.status === 404 && (c.req.method === "GET" || c.req.method === "HEAD") && c.req.path !== "/" && c.req.path.at(-1) === "/") {
|
|
6
6
|
const url = new URL(c.req.url);
|
|
7
7
|
url.pathname = url.pathname.substring(0, url.pathname.length - 1);
|
|
8
8
|
c.res = c.redirect(url.toString(), 301);
|
|
@@ -12,7 +12,7 @@ var trimTrailingSlash = () => {
|
|
|
12
12
|
var appendTrailingSlash = () => {
|
|
13
13
|
return async function appendTrailingSlash2(c, next) {
|
|
14
14
|
await next();
|
|
15
|
-
if (c.res.status === 404 && c.req.method === "GET" && c.req.path.at(-1) !== "/") {
|
|
15
|
+
if (c.res.status === 404 && (c.req.method === "GET" || c.req.method === "HEAD") && c.req.path.at(-1) !== "/") {
|
|
16
16
|
const url = new URL(c.req.url);
|
|
17
17
|
url.pathname += "/";
|
|
18
18
|
c.res = c.redirect(url.toString(), 301);
|
package/dist/types/context.d.ts
CHANGED
|
@@ -339,7 +339,7 @@ export declare class Context<E extends Env = any, P extends string = any, I exte
|
|
|
339
339
|
* @example
|
|
340
340
|
* ```ts
|
|
341
341
|
* app.use('*', async (c, next) => {
|
|
342
|
-
* c.set('message', 'Hono is
|
|
342
|
+
* c.set('message', 'Hono is hot!!')
|
|
343
343
|
* await next()
|
|
344
344
|
* })
|
|
345
345
|
* ```
|