hono 3.2.0-rc.1 → 3.2.0-rc.2
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/adapter/aws-lambda/handler.js +21 -8
- package/dist/cjs/adapter/aws-lambda/handler.js +23 -9
- package/dist/cjs/context.js +1 -1
- package/dist/cjs/utils/url.js +1 -1
- package/dist/context.js +1 -1
- package/dist/types/adapter/aws-lambda/handler.d.ts +15 -1
- package/dist/utils/url.js +1 -1
- package/package.json +2 -2
|
@@ -9,11 +9,14 @@ var handle = (app) => {
|
|
|
9
9
|
};
|
|
10
10
|
};
|
|
11
11
|
var createResult = async (res) => {
|
|
12
|
+
const contentType = res.headers.get("content-type");
|
|
13
|
+
const isBase64Encoded = contentType && isContentTypeBinary(contentType) ? true : false;
|
|
14
|
+
const body = isBase64Encoded ? await fromReadableToString(res) : await res.text();
|
|
12
15
|
const result = {
|
|
13
|
-
body
|
|
16
|
+
body,
|
|
14
17
|
headers: {},
|
|
15
18
|
statusCode: res.status,
|
|
16
|
-
isBase64Encoded
|
|
19
|
+
isBase64Encoded
|
|
17
20
|
};
|
|
18
21
|
res.headers.forEach((value, key) => {
|
|
19
22
|
result.headers[key] = value;
|
|
@@ -22,16 +25,17 @@ var createResult = async (res) => {
|
|
|
22
25
|
};
|
|
23
26
|
var createRequest = (event) => {
|
|
24
27
|
const queryString = extractQueryString(event);
|
|
25
|
-
const urlPath =
|
|
28
|
+
const urlPath = `https://${event.requestContext.domainName}${isProxyEvent(event) ? event.path : event.rawPath}`;
|
|
26
29
|
const url = queryString ? `${urlPath}?${queryString}` : urlPath;
|
|
27
30
|
const headers = new Headers();
|
|
28
31
|
for (const [k, v] of Object.entries(event.headers)) {
|
|
29
32
|
if (v)
|
|
30
33
|
headers.set(k, v);
|
|
31
34
|
}
|
|
35
|
+
const method = "httpMethod" in event ? event.httpMethod : event.requestContext.http.method;
|
|
32
36
|
const requestInit = {
|
|
33
37
|
headers,
|
|
34
|
-
method
|
|
38
|
+
method
|
|
35
39
|
};
|
|
36
40
|
if (event.body) {
|
|
37
41
|
requestInit.body = event.isBase64Encoded ? atob(event.body) : event.body;
|
|
@@ -39,10 +43,13 @@ var createRequest = (event) => {
|
|
|
39
43
|
return new Request(url, requestInit);
|
|
40
44
|
};
|
|
41
45
|
var extractQueryString = (event) => {
|
|
42
|
-
if (
|
|
43
|
-
return event.
|
|
46
|
+
if (isProxyEvent(event)) {
|
|
47
|
+
return Object.entries(event.queryStringParameters || {}).filter(([, value]) => value).map(([key, value]) => `${key}=${value}`).join("&");
|
|
44
48
|
}
|
|
45
|
-
return
|
|
49
|
+
return isProxyEventV2(event) ? event.rawQueryString : event.rawQueryString;
|
|
50
|
+
};
|
|
51
|
+
var isProxyEvent = (event) => {
|
|
52
|
+
return Object.prototype.hasOwnProperty.call(event, "path");
|
|
46
53
|
};
|
|
47
54
|
var isProxyEventV2 = (event) => {
|
|
48
55
|
return Object.prototype.hasOwnProperty.call(event, "rawPath");
|
|
@@ -56,6 +63,12 @@ var fromReadableToString = async (res) => {
|
|
|
56
63
|
}
|
|
57
64
|
return btoa(string);
|
|
58
65
|
};
|
|
66
|
+
var isContentTypeBinary = (contentType) => {
|
|
67
|
+
return !/^(text\/(plain|html|css|javascript|csv).*|application\/(.*json|.*xml).*|image\/svg\+xml)$/.test(
|
|
68
|
+
contentType
|
|
69
|
+
);
|
|
70
|
+
};
|
|
59
71
|
export {
|
|
60
|
-
handle
|
|
72
|
+
handle,
|
|
73
|
+
isContentTypeBinary
|
|
61
74
|
};
|
|
@@ -24,7 +24,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var handler_exports = {};
|
|
26
26
|
__export(handler_exports, {
|
|
27
|
-
handle: () => handle
|
|
27
|
+
handle: () => handle,
|
|
28
|
+
isContentTypeBinary: () => isContentTypeBinary
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(handler_exports);
|
|
30
31
|
var import_crypto = __toESM(require("crypto"), 1);
|
|
@@ -37,11 +38,14 @@ const handle = (app) => {
|
|
|
37
38
|
};
|
|
38
39
|
};
|
|
39
40
|
const createResult = async (res) => {
|
|
41
|
+
const contentType = res.headers.get("content-type");
|
|
42
|
+
const isBase64Encoded = contentType && isContentTypeBinary(contentType) ? true : false;
|
|
43
|
+
const body = isBase64Encoded ? await fromReadableToString(res) : await res.text();
|
|
40
44
|
const result = {
|
|
41
|
-
body
|
|
45
|
+
body,
|
|
42
46
|
headers: {},
|
|
43
47
|
statusCode: res.status,
|
|
44
|
-
isBase64Encoded
|
|
48
|
+
isBase64Encoded
|
|
45
49
|
};
|
|
46
50
|
res.headers.forEach((value, key) => {
|
|
47
51
|
result.headers[key] = value;
|
|
@@ -50,16 +54,17 @@ const createResult = async (res) => {
|
|
|
50
54
|
};
|
|
51
55
|
const createRequest = (event) => {
|
|
52
56
|
const queryString = extractQueryString(event);
|
|
53
|
-
const urlPath =
|
|
57
|
+
const urlPath = `https://${event.requestContext.domainName}${isProxyEvent(event) ? event.path : event.rawPath}`;
|
|
54
58
|
const url = queryString ? `${urlPath}?${queryString}` : urlPath;
|
|
55
59
|
const headers = new Headers();
|
|
56
60
|
for (const [k, v] of Object.entries(event.headers)) {
|
|
57
61
|
if (v)
|
|
58
62
|
headers.set(k, v);
|
|
59
63
|
}
|
|
64
|
+
const method = "httpMethod" in event ? event.httpMethod : event.requestContext.http.method;
|
|
60
65
|
const requestInit = {
|
|
61
66
|
headers,
|
|
62
|
-
method
|
|
67
|
+
method
|
|
63
68
|
};
|
|
64
69
|
if (event.body) {
|
|
65
70
|
requestInit.body = event.isBase64Encoded ? atob(event.body) : event.body;
|
|
@@ -67,10 +72,13 @@ const createRequest = (event) => {
|
|
|
67
72
|
return new Request(url, requestInit);
|
|
68
73
|
};
|
|
69
74
|
const extractQueryString = (event) => {
|
|
70
|
-
if (
|
|
71
|
-
return event.
|
|
75
|
+
if (isProxyEvent(event)) {
|
|
76
|
+
return Object.entries(event.queryStringParameters || {}).filter(([, value]) => value).map(([key, value]) => `${key}=${value}`).join("&");
|
|
72
77
|
}
|
|
73
|
-
return
|
|
78
|
+
return isProxyEventV2(event) ? event.rawQueryString : event.rawQueryString;
|
|
79
|
+
};
|
|
80
|
+
const isProxyEvent = (event) => {
|
|
81
|
+
return Object.prototype.hasOwnProperty.call(event, "path");
|
|
74
82
|
};
|
|
75
83
|
const isProxyEventV2 = (event) => {
|
|
76
84
|
return Object.prototype.hasOwnProperty.call(event, "rawPath");
|
|
@@ -84,7 +92,13 @@ const fromReadableToString = async (res) => {
|
|
|
84
92
|
}
|
|
85
93
|
return btoa(string);
|
|
86
94
|
};
|
|
95
|
+
const isContentTypeBinary = (contentType) => {
|
|
96
|
+
return !/^(text\/(plain|html|css|javascript|csv).*|application\/(.*json|.*xml).*|image\/svg\+xml)$/.test(
|
|
97
|
+
contentType
|
|
98
|
+
);
|
|
99
|
+
};
|
|
87
100
|
// Annotate the CommonJS export names for ESM import in node:
|
|
88
101
|
0 && (module.exports = {
|
|
89
|
-
handle
|
|
102
|
+
handle,
|
|
103
|
+
isContentTypeBinary
|
|
90
104
|
});
|
package/dist/cjs/context.js
CHANGED
|
@@ -138,7 +138,7 @@ class Context {
|
|
|
138
138
|
this._pH = {};
|
|
139
139
|
}
|
|
140
140
|
if (this._pH["content-type"]) {
|
|
141
|
-
this._pH["content-type"] = "text/plain; charset=
|
|
141
|
+
this._pH["content-type"] = "text/plain; charset=UTF-8";
|
|
142
142
|
}
|
|
143
143
|
return typeof arg === "number" ? this.newResponse(text, arg, headers) : this.newResponse(text, arg);
|
|
144
144
|
};
|
package/dist/cjs/utils/url.js
CHANGED
|
@@ -149,7 +149,7 @@ const _getQueryParam = (url, key, multiple) => {
|
|
|
149
149
|
} else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
|
|
150
150
|
return "";
|
|
151
151
|
}
|
|
152
|
-
keyIndex2 = url.indexOf(`&${key}`, keyIndex2);
|
|
152
|
+
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
153
153
|
}
|
|
154
154
|
encoded = /[%+]/.test(url);
|
|
155
155
|
if (!encoded) {
|
package/dist/context.js
CHANGED
|
@@ -116,7 +116,7 @@ var Context = class {
|
|
|
116
116
|
this._pH = {};
|
|
117
117
|
}
|
|
118
118
|
if (this._pH["content-type"]) {
|
|
119
|
-
this._pH["content-type"] = "text/plain; charset=
|
|
119
|
+
this._pH["content-type"] = "text/plain; charset=UTF-8";
|
|
120
120
|
}
|
|
121
121
|
return typeof arg === "number" ? this.newResponse(text, arg, headers) : this.newResponse(text, arg);
|
|
122
122
|
};
|
|
@@ -21,6 +21,19 @@ interface APIGatewayProxyEvent {
|
|
|
21
21
|
domainName: string;
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
+
interface LambdaFunctionUrlEvent {
|
|
25
|
+
headers: Record<string, string | undefined>;
|
|
26
|
+
rawPath: string;
|
|
27
|
+
rawQueryString: string;
|
|
28
|
+
body: string | null;
|
|
29
|
+
isBase64Encoded: boolean;
|
|
30
|
+
requestContext: {
|
|
31
|
+
domainName: string;
|
|
32
|
+
http: {
|
|
33
|
+
method: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
}
|
|
24
37
|
interface APIGatewayProxyResult {
|
|
25
38
|
statusCode: number;
|
|
26
39
|
body: string;
|
|
@@ -30,5 +43,6 @@ interface APIGatewayProxyResult {
|
|
|
30
43
|
/**
|
|
31
44
|
* Accepts events from API Gateway/ELB(`APIGatewayProxyEvent`) and directly through Function Url(`APIGatewayProxyEventV2`)
|
|
32
45
|
*/
|
|
33
|
-
export declare const handle: (app: Hono) => (event: APIGatewayProxyEvent | APIGatewayProxyEventV2) => Promise<APIGatewayProxyResult>;
|
|
46
|
+
export declare const handle: (app: Hono) => (event: APIGatewayProxyEvent | APIGatewayProxyEventV2 | LambdaFunctionUrlEvent) => Promise<APIGatewayProxyResult>;
|
|
47
|
+
export declare const isContentTypeBinary: (contentType: string) => boolean;
|
|
34
48
|
export {};
|
package/dist/utils/url.js
CHANGED
|
@@ -118,7 +118,7 @@ var _getQueryParam = (url, key, multiple) => {
|
|
|
118
118
|
} else if (trailingKeyCode == 38 || isNaN(trailingKeyCode)) {
|
|
119
119
|
return "";
|
|
120
120
|
}
|
|
121
|
-
keyIndex2 = url.indexOf(`&${key}`, keyIndex2);
|
|
121
|
+
keyIndex2 = url.indexOf(`&${key}`, keyIndex2 + 1);
|
|
122
122
|
}
|
|
123
123
|
encoded = /[%+]/.test(url);
|
|
124
124
|
if (!encoded) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono",
|
|
3
|
-
"version": "3.2.0-rc.
|
|
3
|
+
"version": "3.2.0-rc.2",
|
|
4
4
|
"description": "Ultrafast web framework for the Edge",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -358,7 +358,7 @@
|
|
|
358
358
|
"jest-preset-fastly-js-compute": "^0.6.1",
|
|
359
359
|
"msw": "^1.0.0",
|
|
360
360
|
"node-fetch": "2",
|
|
361
|
-
"np": "^7.
|
|
361
|
+
"np": "^7.7.0",
|
|
362
362
|
"prettier": "^2.6.2",
|
|
363
363
|
"publint": "^0.1.8",
|
|
364
364
|
"rimraf": "^3.0.2",
|