Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request body of type ReadableStream omitted when MockAgent["disableNetConnect"] enabled #2418

Closed
mpint opened this issue Nov 9, 2023 · 1 comment · Fixed by #2425
Closed
Labels
bug Something isn't working

Comments

@mpint
Copy link

mpint commented Nov 9, 2023

Bug Description

Request bodies of type ReadableStream are omitted when MockAgent["disableNetConnect"] (or enableNetConnect(url)) is enabled.

This bug was originally filed under miniflare/workers-sdk, but was subsequently diagnosed as an undici issue.

Reproducible By

Please see this issue for a reproduction within a Cloudflare. A diagnosis of the root cause is included in the OP in the "Diagnosis" section.

Courtesy of @mrbbot

import http from "node:http";
import { MockAgent, setGlobalDispatcher, fetch } from "undici";

function startServer() {
  const server = http.createServer((req, res) => {
    res.write(`${req.method} `);
    req.pipe(res);
  });
  
  return new Promise((resolve) => {
    server.listen(0, () => {
      resolve(new URL(`http://127.0.0.1:${server.address().port}`));
    });
  });
}

const url = await startServer();

const fetchMock = new MockAgent();
fetchMock.enableNetConnect(url.host);
setGlobalDispatcher(fetchMock);

const res1 = await fetch(url, {
  method: "POST",
  body: "hello"
});
console.log({ res1: await res1.text() }); // "POST hello"

const res2 = await fetch(url, {
  method: "POST",
  body: new Blob(["hello"]).stream(),
  duplex: "half"
});
console.log({ res2: await res2.text() }); // "POST" (no body)

Expected Behavior

Body should be sent in res2

Environment

Node 18x, OSX 13.6

@mpint mpint added the bug Something isn't working label Nov 9, 2023
@mpint mpint changed the title [MockAgent] ReadableStream request body omitted in mocked requests [MockAgent] Request body of type ReadableStream omitted in mocked requests Nov 9, 2023
@mpint mpint changed the title [MockAgent] Request body of type ReadableStream omitted in mocked requests Request body of type ReadableStream omitted when MockAgent["disableNetConnect"] enabled Nov 9, 2023
@tsctx
Copy link
Member

tsctx commented Nov 11, 2023

Hi @mpint,
This issue will be fixed in #2425.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants