Skip to content

Commit

Permalink
fix(proxyRequest): only attempt to read body if incoming request can …
Browse files Browse the repository at this point in the history
…contain body
  • Loading branch information
pi0 committed Aug 1, 2023
1 parent d97e921 commit a26579f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/utils/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { H3Event } from "../event";
import type { H3EventContext, RequestHeaders } from "../types";
import { getMethod, getRequestHeaders } from "./request";
import { getRequestHeaders } from "./request";
import { splitCookiesString } from "./cookie";
import { sanitizeStatusMessage, sanitizeStatusCode } from "./sanitize";
import { readRawBody } from "./body";
Expand Down Expand Up @@ -35,13 +35,10 @@ export async function proxyRequest(
target: string,
opts: ProxyOptions = {}
) {
// Method
const method = opts.fetchOptions?.method || getMethod(event);

// Body
// Request Body
let body;
let duplex: Duplex | undefined;
if (PayloadMethods.has(method)) {
if (PayloadMethods.has(event.method!)) {
if (opts.streamRequest) {
body = event.body;
duplex = "half";
Expand All @@ -50,6 +47,9 @@ export async function proxyRequest(
}
}

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

// Headers
const fetchHeaders = mergeHeaders(
getProxyRequestHeaders(event),
Expand Down

0 comments on commit a26579f

Please sign in to comment.