@kiyasov/platform-hono 1.3.9 → 1.3.10
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/src/adapters/hono-adapter.d.ts +2 -2
- package/dist/cjs/src/adapters/hono-adapter.js +21 -5
- package/dist/cjs/src/adapters/hono-adapter.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/adapters/hono-adapter.d.ts +2 -2
- package/dist/esm/src/adapters/hono-adapter.js +21 -5
- package/dist/esm/src/adapters/hono-adapter.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/adapters/hono-adapter.ts +24 -5
package/package.json
CHANGED
|
@@ -126,7 +126,7 @@ export class HonoAdapter extends AbstractHttpAdapter<
|
|
|
126
126
|
public async reply(ctx: Context, body: any, statusCode?: StatusCode) {
|
|
127
127
|
if (statusCode) ctx.status(statusCode);
|
|
128
128
|
|
|
129
|
-
const responseContentType = this.getHeader(ctx, "Content-Type");
|
|
129
|
+
const responseContentType = await this.getHeader(ctx, "Content-Type");
|
|
130
130
|
if (
|
|
131
131
|
!responseContentType?.startsWith("application/json") &&
|
|
132
132
|
body?.statusCode >= HttpStatus.BAD_REQUEST
|
|
@@ -205,8 +205,19 @@ export class HonoAdapter extends AbstractHttpAdapter<
|
|
|
205
205
|
return true;
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
public getHeader?(
|
|
209
|
-
|
|
208
|
+
public async getHeader?(
|
|
209
|
+
ctx: Context | (() => Promise<Context>),
|
|
210
|
+
name: string
|
|
211
|
+
) {
|
|
212
|
+
if (typeof ctx === "function") {
|
|
213
|
+
ctx = await ctx();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (ctx && typeof ctx.req.header === "function") {
|
|
217
|
+
return ctx.req.header(name);
|
|
218
|
+
} else {
|
|
219
|
+
throw new Error("Invalid context: get method not found on context.");
|
|
220
|
+
}
|
|
210
221
|
}
|
|
211
222
|
|
|
212
223
|
public async setHeader(
|
|
@@ -241,8 +252,16 @@ export class HonoAdapter extends AbstractHttpAdapter<
|
|
|
241
252
|
}
|
|
242
253
|
}
|
|
243
254
|
|
|
244
|
-
public getRequestHostname(ctx: Context)
|
|
245
|
-
|
|
255
|
+
public async getRequestHostname(ctx: Context | (() => Promise<Context>)) {
|
|
256
|
+
if (typeof ctx === "function") {
|
|
257
|
+
ctx = await ctx();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (ctx && typeof ctx.req.header === "function") {
|
|
261
|
+
return ctx.req.header("host");
|
|
262
|
+
} else {
|
|
263
|
+
throw new Error("Invalid context: get method not found on context.");
|
|
264
|
+
}
|
|
246
265
|
}
|
|
247
266
|
|
|
248
267
|
public getRequestMethod(request: HonoRequest): string {
|