Skip to content

Commit 7585861

Browse files
committed
refactor(event): always normalize event.method
1 parent a26579f commit 7585861

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/event/event.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,13 @@ export class H3Event<
7373
);
7474
}
7575

76-
get method(): HTTPMethod | undefined {
77-
return this._method || (this.node.req.method as HTTPMethod);
76+
get method(): HTTPMethod {
77+
if (!this._method) {
78+
this._method = (
79+
this.node.req.method || "GET"
80+
).toUpperCase() as HTTPMethod;
81+
}
82+
return this._method;
7883
}
7984

8085
get headers(): Headers {

src/utils/proxy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export async function proxyRequest(
3838
// Request Body
3939
let body;
4040
let duplex: Duplex | undefined;
41-
if (PayloadMethods.has(event.method!)) {
41+
if (PayloadMethods.has(event.method)) {
4242
if (opts.streamRequest) {
4343
body = event.body;
4444
duplex = "half";
@@ -48,7 +48,7 @@ export async function proxyRequest(
4848
}
4949

5050
// Method
51-
const method = opts.fetchOptions?.method || event.method!;
51+
const method = opts.fetchOptions?.method || event.method;
5252

5353
// Headers
5454
const fetchHeaders = mergeHeaders(

0 commit comments

Comments
 (0)