hono 4.12.30 → 4.12.32
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/helper/streaming/sse.js +5 -4
- package/dist/cjs/middleware/secure-headers/secure-headers.js +10 -4
- package/dist/cjs/request.js +8 -3
- package/dist/cjs/utils/accept.js +1 -1
- package/dist/cjs/utils/body.js +6 -0
- package/dist/cjs/utils/url.js +1 -1
- package/dist/helper/streaming/sse.js +5 -4
- package/dist/middleware/secure-headers/secure-headers.js +10 -4
- package/dist/request.js +8 -3
- package/dist/types/adapter/aws-lambda/types.d.ts +9 -0
- package/dist/types/middleware/combine/index.d.ts +1 -1
- package/dist/utils/accept.js +1 -1
- package/dist/utils/body.js +6 -0
- package/dist/utils/url.js +1 -1
- package/package.json +1 -1
|
@@ -33,16 +33,17 @@ class SSEStreamingApi extends import_stream.StreamingApi {
|
|
|
33
33
|
const dataLines = data.split(/\r\n|\r|\n/).map((line) => {
|
|
34
34
|
return `data: ${line}`;
|
|
35
35
|
}).join("\n");
|
|
36
|
-
for (const key of ["event", "id"
|
|
37
|
-
|
|
36
|
+
for (const key of ["event", "id"]) {
|
|
37
|
+
const value = message[key];
|
|
38
|
+
if (value && /[\r\n]/.test(value)) {
|
|
38
39
|
throw new Error(`${key} must not contain "\\r" or "\\n"`);
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
const sseData = [
|
|
42
43
|
message.event && `event: ${message.event}`,
|
|
43
44
|
dataLines,
|
|
44
|
-
message.id && `id: ${message.id}`,
|
|
45
|
-
message.retry && `retry: ${message.retry}`
|
|
45
|
+
message.id !== void 0 && `id: ${message.id}`,
|
|
46
|
+
message.retry !== void 0 && `retry: ${message.retry}`
|
|
46
47
|
].filter(Boolean).join("\n") + "\n\n";
|
|
47
48
|
await this.write(sseData);
|
|
48
49
|
}
|
|
@@ -71,14 +71,20 @@ const secureHeaders = (customOptions) => {
|
|
|
71
71
|
const headersToSet = getFilteredHeaders(options);
|
|
72
72
|
const callbacks = [];
|
|
73
73
|
if (options.contentSecurityPolicy) {
|
|
74
|
-
const [callback, value] = getCSPDirectives(
|
|
74
|
+
const [callback, value] = getCSPDirectives(
|
|
75
|
+
options.contentSecurityPolicy,
|
|
76
|
+
"Content-Security-Policy"
|
|
77
|
+
);
|
|
75
78
|
if (callback) {
|
|
76
79
|
callbacks.push(callback);
|
|
77
80
|
}
|
|
78
81
|
headersToSet.push(["Content-Security-Policy", value]);
|
|
79
82
|
}
|
|
80
83
|
if (options.contentSecurityPolicyReportOnly) {
|
|
81
|
-
const [callback, value] = getCSPDirectives(
|
|
84
|
+
const [callback, value] = getCSPDirectives(
|
|
85
|
+
options.contentSecurityPolicyReportOnly,
|
|
86
|
+
"Content-Security-Policy-Report-Only"
|
|
87
|
+
);
|
|
82
88
|
if (callback) {
|
|
83
89
|
callbacks.push(callback);
|
|
84
90
|
}
|
|
@@ -111,7 +117,7 @@ function getFilteredHeaders(options) {
|
|
|
111
117
|
return typeof overrideValue === "string" ? [defaultValue[0], overrideValue] : defaultValue;
|
|
112
118
|
});
|
|
113
119
|
}
|
|
114
|
-
function getCSPDirectives(contentSecurityPolicy) {
|
|
120
|
+
function getCSPDirectives(contentSecurityPolicy, headerName) {
|
|
115
121
|
const callbacks = [];
|
|
116
122
|
const resultValues = [];
|
|
117
123
|
for (const [directive, value] of Object.entries(contentSecurityPolicy)) {
|
|
@@ -136,7 +142,7 @@ function getCSPDirectives(contentSecurityPolicy) {
|
|
|
136
142
|
resultValues.pop();
|
|
137
143
|
return callbacks.length === 0 ? [void 0, resultValues.join("")] : [
|
|
138
144
|
(ctx, headersToSet) => headersToSet.map((values) => {
|
|
139
|
-
if (values[0] ===
|
|
145
|
+
if (values[0] === headerName) {
|
|
140
146
|
const clone = values[1].slice();
|
|
141
147
|
callbacks.forEach((cb) => {
|
|
142
148
|
cb(ctx, clone);
|
package/dist/cjs/request.js
CHANGED
|
@@ -98,7 +98,7 @@ class HonoRequest {
|
|
|
98
98
|
if (name) {
|
|
99
99
|
return this.raw.headers.get(name) ?? void 0;
|
|
100
100
|
}
|
|
101
|
-
const headerData =
|
|
101
|
+
const headerData = /* @__PURE__ */ Object.create(null);
|
|
102
102
|
this.raw.headers.forEach((value, key) => {
|
|
103
103
|
headerData[key] = value;
|
|
104
104
|
});
|
|
@@ -316,11 +316,16 @@ const cloneRawRequest = async (req) => {
|
|
|
316
316
|
message: "Cannot clone request: body was already consumed and not cached. Please use HonoRequest methods (e.g., req.json(), req.text()) instead of consuming req.raw directly."
|
|
317
317
|
});
|
|
318
318
|
}
|
|
319
|
+
const body = await req[cacheKey]();
|
|
320
|
+
const headers = req.header();
|
|
321
|
+
if (body instanceof FormData) {
|
|
322
|
+
delete headers["content-type"];
|
|
323
|
+
}
|
|
319
324
|
const requestInit = {
|
|
320
|
-
body
|
|
325
|
+
body,
|
|
321
326
|
cache: req.raw.cache,
|
|
322
327
|
credentials: req.raw.credentials,
|
|
323
|
-
headers
|
|
328
|
+
headers,
|
|
324
329
|
integrity: req.raw.integrity,
|
|
325
330
|
keepalive: req.raw.keepalive,
|
|
326
331
|
method: req.method,
|
package/dist/cjs/utils/accept.js
CHANGED
|
@@ -146,7 +146,7 @@ const getNextParam = (acceptHeader, startIndex) => {
|
|
|
146
146
|
const getNextAcceptValue = (acceptHeader, startIndex) => {
|
|
147
147
|
const accept = {
|
|
148
148
|
type: "",
|
|
149
|
-
params:
|
|
149
|
+
params: /* @__PURE__ */ Object.create(null),
|
|
150
150
|
q: 1
|
|
151
151
|
};
|
|
152
152
|
startIndex = consumeWhitespace(acceptHeader, startIndex);
|
package/dist/cjs/utils/body.js
CHANGED
|
@@ -33,6 +33,12 @@ const parseBody = async (request, options = /* @__PURE__ */ Object.create(null))
|
|
|
33
33
|
return {};
|
|
34
34
|
};
|
|
35
35
|
async function parseFormData(request, options) {
|
|
36
|
+
if (!isRawRequest(request) && request.bodyCache.formData) {
|
|
37
|
+
return convertFormDataToBodyData(
|
|
38
|
+
await request.bodyCache.formData,
|
|
39
|
+
options
|
|
40
|
+
);
|
|
41
|
+
}
|
|
36
42
|
const headers = isRawRequest(request) ? request.headers : request.raw.headers;
|
|
37
43
|
const arrayBuffer = await request.arrayBuffer();
|
|
38
44
|
const formDataPromise = (0, import_buffer.bufferToFormData)(arrayBuffer, headers.get("Content-Type") || "");
|
package/dist/cjs/utils/url.js
CHANGED
|
@@ -192,7 +192,7 @@ const _getQueryParam = (url, key, multiple) => {
|
|
|
192
192
|
return void 0;
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
|
-
const results =
|
|
195
|
+
const results = /* @__PURE__ */ Object.create(null);
|
|
196
196
|
encoded ??= /[%+]/.test(url);
|
|
197
197
|
let keyIndex = url.indexOf("?", 8);
|
|
198
198
|
while (keyIndex !== -1) {
|
|
@@ -11,16 +11,17 @@ var SSEStreamingApi = class extends StreamingApi {
|
|
|
11
11
|
const dataLines = data.split(/\r\n|\r|\n/).map((line) => {
|
|
12
12
|
return `data: ${line}`;
|
|
13
13
|
}).join("\n");
|
|
14
|
-
for (const key of ["event", "id"
|
|
15
|
-
|
|
14
|
+
for (const key of ["event", "id"]) {
|
|
15
|
+
const value = message[key];
|
|
16
|
+
if (value && /[\r\n]/.test(value)) {
|
|
16
17
|
throw new Error(`${key} must not contain "\\r" or "\\n"`);
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
const sseData = [
|
|
20
21
|
message.event && `event: ${message.event}`,
|
|
21
22
|
dataLines,
|
|
22
|
-
message.id && `id: ${message.id}`,
|
|
23
|
-
message.retry && `retry: ${message.retry}`
|
|
23
|
+
message.id !== void 0 && `id: ${message.id}`,
|
|
24
|
+
message.retry !== void 0 && `retry: ${message.retry}`
|
|
24
25
|
].filter(Boolean).join("\n") + "\n\n";
|
|
25
26
|
await this.write(sseData);
|
|
26
27
|
}
|
|
@@ -49,14 +49,20 @@ var secureHeaders = (customOptions) => {
|
|
|
49
49
|
const headersToSet = getFilteredHeaders(options);
|
|
50
50
|
const callbacks = [];
|
|
51
51
|
if (options.contentSecurityPolicy) {
|
|
52
|
-
const [callback, value] = getCSPDirectives(
|
|
52
|
+
const [callback, value] = getCSPDirectives(
|
|
53
|
+
options.contentSecurityPolicy,
|
|
54
|
+
"Content-Security-Policy"
|
|
55
|
+
);
|
|
53
56
|
if (callback) {
|
|
54
57
|
callbacks.push(callback);
|
|
55
58
|
}
|
|
56
59
|
headersToSet.push(["Content-Security-Policy", value]);
|
|
57
60
|
}
|
|
58
61
|
if (options.contentSecurityPolicyReportOnly) {
|
|
59
|
-
const [callback, value] = getCSPDirectives(
|
|
62
|
+
const [callback, value] = getCSPDirectives(
|
|
63
|
+
options.contentSecurityPolicyReportOnly,
|
|
64
|
+
"Content-Security-Policy-Report-Only"
|
|
65
|
+
);
|
|
60
66
|
if (callback) {
|
|
61
67
|
callbacks.push(callback);
|
|
62
68
|
}
|
|
@@ -89,7 +95,7 @@ function getFilteredHeaders(options) {
|
|
|
89
95
|
return typeof overrideValue === "string" ? [defaultValue[0], overrideValue] : defaultValue;
|
|
90
96
|
});
|
|
91
97
|
}
|
|
92
|
-
function getCSPDirectives(contentSecurityPolicy) {
|
|
98
|
+
function getCSPDirectives(contentSecurityPolicy, headerName) {
|
|
93
99
|
const callbacks = [];
|
|
94
100
|
const resultValues = [];
|
|
95
101
|
for (const [directive, value] of Object.entries(contentSecurityPolicy)) {
|
|
@@ -114,7 +120,7 @@ function getCSPDirectives(contentSecurityPolicy) {
|
|
|
114
120
|
resultValues.pop();
|
|
115
121
|
return callbacks.length === 0 ? [void 0, resultValues.join("")] : [
|
|
116
122
|
(ctx, headersToSet) => headersToSet.map((values) => {
|
|
117
|
-
if (values[0] ===
|
|
123
|
+
if (values[0] === headerName) {
|
|
118
124
|
const clone = values[1].slice();
|
|
119
125
|
callbacks.forEach((cb) => {
|
|
120
126
|
cb(ctx, clone);
|
package/dist/request.js
CHANGED
|
@@ -76,7 +76,7 @@ var HonoRequest = class {
|
|
|
76
76
|
if (name) {
|
|
77
77
|
return this.raw.headers.get(name) ?? void 0;
|
|
78
78
|
}
|
|
79
|
-
const headerData =
|
|
79
|
+
const headerData = /* @__PURE__ */ Object.create(null);
|
|
80
80
|
this.raw.headers.forEach((value, key) => {
|
|
81
81
|
headerData[key] = value;
|
|
82
82
|
});
|
|
@@ -294,11 +294,16 @@ var cloneRawRequest = async (req) => {
|
|
|
294
294
|
message: "Cannot clone request: body was already consumed and not cached. Please use HonoRequest methods (e.g., req.json(), req.text()) instead of consuming req.raw directly."
|
|
295
295
|
});
|
|
296
296
|
}
|
|
297
|
+
const body = await req[cacheKey]();
|
|
298
|
+
const headers = req.header();
|
|
299
|
+
if (body instanceof FormData) {
|
|
300
|
+
delete headers["content-type"];
|
|
301
|
+
}
|
|
297
302
|
const requestInit = {
|
|
298
|
-
body
|
|
303
|
+
body,
|
|
299
304
|
cache: req.raw.cache,
|
|
300
305
|
credentials: req.raw.credentials,
|
|
301
|
-
headers
|
|
306
|
+
headers,
|
|
302
307
|
integrity: req.raw.integrity,
|
|
303
308
|
keepalive: req.raw.keepalive,
|
|
304
309
|
method: req.method,
|
|
@@ -96,6 +96,15 @@ interface Authorizer {
|
|
|
96
96
|
userArn: string;
|
|
97
97
|
userId: string;
|
|
98
98
|
};
|
|
99
|
+
jwt?: {
|
|
100
|
+
claims: Record<string, string | number | boolean | string[]>;
|
|
101
|
+
scopes: string[] | null;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* The `context` object returned by a Lambda (REQUEST) authorizer.
|
|
105
|
+
* It is `null` when the authorizer returns no context.
|
|
106
|
+
*/
|
|
107
|
+
lambda?: Record<string, unknown> | null;
|
|
99
108
|
}
|
|
100
109
|
export interface ApiGatewayRequestContextV2 {
|
|
101
110
|
accountId: string;
|
|
@@ -71,7 +71,7 @@ export declare const every: (...middleware: (MiddlewareHandler | Condition)[]) =
|
|
|
71
71
|
* @example
|
|
72
72
|
* ```ts
|
|
73
73
|
* import { except } from 'hono/combine'
|
|
74
|
-
* import { bearerAuth } from 'hono/bearer-auth
|
|
74
|
+
* import { bearerAuth } from 'hono/bearer-auth'
|
|
75
75
|
*
|
|
76
76
|
* // If client is accessing public API, then skip authentication.
|
|
77
77
|
* // Otherwise, require a valid token.
|
package/dist/utils/accept.js
CHANGED
|
@@ -125,7 +125,7 @@ var getNextParam = (acceptHeader, startIndex) => {
|
|
|
125
125
|
var getNextAcceptValue = (acceptHeader, startIndex) => {
|
|
126
126
|
const accept = {
|
|
127
127
|
type: "",
|
|
128
|
-
params:
|
|
128
|
+
params: /* @__PURE__ */ Object.create(null),
|
|
129
129
|
q: 1
|
|
130
130
|
};
|
|
131
131
|
startIndex = consumeWhitespace(acceptHeader, startIndex);
|
package/dist/utils/body.js
CHANGED
|
@@ -12,6 +12,12 @@ var parseBody = async (request, options = /* @__PURE__ */ Object.create(null)) =
|
|
|
12
12
|
return {};
|
|
13
13
|
};
|
|
14
14
|
async function parseFormData(request, options) {
|
|
15
|
+
if (!isRawRequest(request) && request.bodyCache.formData) {
|
|
16
|
+
return convertFormDataToBodyData(
|
|
17
|
+
await request.bodyCache.formData,
|
|
18
|
+
options
|
|
19
|
+
);
|
|
20
|
+
}
|
|
15
21
|
const headers = isRawRequest(request) ? request.headers : request.raw.headers;
|
|
16
22
|
const arrayBuffer = await request.arrayBuffer();
|
|
17
23
|
const formDataPromise = bufferToFormData(arrayBuffer, headers.get("Content-Type") || "");
|
package/dist/utils/url.js
CHANGED
|
@@ -159,7 +159,7 @@ var _getQueryParam = (url, key, multiple) => {
|
|
|
159
159
|
return void 0;
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
-
const results =
|
|
162
|
+
const results = /* @__PURE__ */ Object.create(null);
|
|
163
163
|
encoded ??= /[%+]/.test(url);
|
|
164
164
|
let keyIndex = url.indexOf("?", 8);
|
|
165
165
|
while (keyIndex !== -1) {
|