Skip to content

Commit

Permalink
refactor(event): rename event.body to event.rawBody
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 8, 2023
1 parent aa2e5d9 commit 563313d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/event/event.ts
Expand Up @@ -93,7 +93,8 @@ export class H3Event<
return this.node.res;
}

get body() {
/** @experimental */
get rawBody() {
if (!this._hasBody) {
return undefined;
}
Expand Down Expand Up @@ -123,7 +124,7 @@ export class H3Event<
duplex: "half",
method: this.method,
headers: this.headers,
body: this.body,
body: this.rawBody,
});
}
return this._request;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/proxy.ts
Expand Up @@ -40,7 +40,7 @@ export async function proxyRequest(
let duplex: Duplex | undefined;
if (PayloadMethods.has(event.method)) {
if (opts.streamRequest) {
body = event.body;
body = event.rawBody;
duplex = "half";
} else {
body = await readRawBody(event, false).catch(() => undefined);
Expand Down
2 changes: 1 addition & 1 deletion test/event.test.ts
Expand Up @@ -57,7 +57,7 @@ describe("Event", () => {
app.use(
"/",
eventHandler(async (event) => {
const bodyStream = event.body as unknown as NodeJS.ReadableStream;
const bodyStream = event.rawBody as unknown as NodeJS.ReadableStream;
let bytes = 0;
for await (const chunk of bodyStream) {
bytes += chunk.length;
Expand Down

0 comments on commit 563313d

Please sign in to comment.