Skip to content

Commit

Permalink
refactor(event): always normalize event.method
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 1, 2023
1 parent a26579f commit 7585861
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/event/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@ export class H3Event<
);
}

get method(): HTTPMethod | undefined {
return this._method || (this.node.req.method as HTTPMethod);
get method(): HTTPMethod {
if (!this._method) {
this._method = (
this.node.req.method || "GET"
).toUpperCase() as HTTPMethod;
}
return this._method;
}

get headers(): Headers {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function proxyRequest(
// Request Body
let body;
let duplex: Duplex | undefined;
if (PayloadMethods.has(event.method!)) {
if (PayloadMethods.has(event.method)) {
if (opts.streamRequest) {
body = event.body;
duplex = "half";
Expand All @@ -48,7 +48,7 @@ export async function proxyRequest(
}

// Method
const method = opts.fetchOptions?.method || event.method!;
const method = opts.fetchOptions?.method || event.method;

// Headers
const fetchHeaders = mergeHeaders(
Expand Down

0 comments on commit 7585861

Please sign in to comment.