Skip to content

Commit cfedf1c

Browse files
committed
fix: pass hono request into buildRequest
1 parent 44dfef5 commit cfedf1c

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/Hono.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Request } from "./process/Request.mjs";
77
/***************** Processing *****************/
88

99
export default new Hono().all("/:rest{.*}", async c => {
10-
let $request = await HonoWorkerAdapter.buildRequest(c);
10+
let $request = await HonoWorkerAdapter.buildRequest(c.req);
1111
let $response;
1212
const KV = c.env ? new Storage({ env: { namespaces: new Map([["", c.env.PersistentStore], ["@iRingo.Maps.Caches", c.env.Maps]]) } }) : undefined;
1313
({ $request, $response } = await Request($request, KV));

src/class/HonoWorkerAdapter.mjs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
* @typedef {import("hono").Context} HonoContext
55
*/
66

7+
/**
8+
* Hono 请求类型。
9+
* Hono request type.
10+
* @typedef {HonoContext["req"]} HonoRequest
11+
*/
12+
713
/**
814
* Worker 统一头部字典。
915
* Worker normalized header dictionary.
@@ -88,22 +94,22 @@ export default class HonoWorkerAdapter {
8894
}
8995

9096
/**
91-
* 从 Hono context 构造内部统一请求对象。
92-
* Build the normalized internal request payload from Hono context.
93-
* @param {HonoContext} c Hono 上下文 / Hono context.
97+
* 从 Hono request 构造内部统一请求对象。
98+
* Build the normalized internal request payload from Hono request.
99+
* @param {HonoRequest} req Hono 请求 / Hono request.
94100
* @returns {Promise<WorkerRequest>} 标准化请求对象 / Normalized request object.
95101
*/
96-
static async buildRequest(c) {
97-
const url = HonoWorkerAdapter.routeRewrite(new URL(c.req.url), c.req.param("rest"));
98-
const method = c.req.method;
102+
static async buildRequest(req) {
103+
const url = HonoWorkerAdapter.routeRewrite(new URL(req.url), req.param("rest"));
104+
const method = req.method;
99105
let bodyBytes;
100106
switch (method) {
101107
case "GET":
102108
case "HEAD":
103109
case "OPTIONS":
104110
break;
105111
default:
106-
bodyBytes = await c.req.arrayBuffer().catch(error => {
112+
bodyBytes = await req.arrayBuffer().catch(error => {
107113
console.info(error);
108114
return undefined;
109115
});
@@ -113,7 +119,7 @@ export default class HonoWorkerAdapter {
113119
return {
114120
method,
115121
url: url.toString(),
116-
headers: HonoWorkerAdapter.normalizeRequestHeaders(c.req.header()),
122+
headers: HonoWorkerAdapter.normalizeRequestHeaders(req.header()),
117123
body: bodyBytes,
118124
bodyBytes,
119125
};

0 commit comments

Comments
 (0)