Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/rules/requests/request-step-impls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ function returnsOriginalBody(
resultingHeaders: Headers
) {
if (result?.rawBody) return result.rawBody === originalBody.buffer;
if (result?.json) return false;
if (result?.json !== undefined) return false;

const returnedBody: unknown = result?.body;
const isSameBody = returnedBody === originalBody || returnedBody === originalBody.buffer;
Expand Down
19 changes: 19 additions & 0 deletions test/integration/proxying/http-proxying.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,25 @@ nodeOnly(() => {
expect(response).to.deep.equal({ hello: "world" });
});

it("should rewrite a spread request's body with a falsy JSON value", async () => {
await remoteServer.forAnyRequest().thenCallback(async (req) => ({
status: 200,
body: await req.body.getText()
}));

for (const value of [false, 0, '', null]) {
await server.reset();
await server.forPost(remoteServer.urlFor("/")).thenPassThrough({
beforeRequest: (req) => ({ ...req, body: req.body.buffer, json: value })
});

const response = await request.post(remoteServer.urlFor("/"), {
body: 'original body'
});
expect(response).to.equal(JSON.stringify(value));
}
});

it("should be able to rewrite a request's body as JSON and encode it automatically", async () => {
await remoteServer.forAnyRequest().thenCallback(async (req) => ({
status: 200,
Expand Down