For some reason it does not like the origin key. If it is removed the this works as expected.
So fix is easy in in userland. In theory. Unfortunately I'm using @elastic/elasticsearch which is creating requests like this internally in some situations and I have no control over it.
Here's a jest test reproducing the error
import http from "http";
import { setupServer } from "msw/node";
test("can make raw passthrough request with an object", async () => {
const mockServer = setupServer(); // No interceptors!
mockServer.listen();
// Real server handling the pass through
const server = http.createServer((req, res) => {
res.writeHead(200, { "Content-Type": "text/plain" });
res.end("Hello from real server");
});
await new Promise<void>((resolve) => {
server.listen(3728, () => {
resolve();
});
});
const doGet = async () => {
return await new Promise<http.IncomingMessage>((resolve, reject) => {
http.request(
{
hostname: "localhost",
path: "/",
origin: "http://localhost:3728",
port: 3728,
method: "GET",
},
resolve,
)
.on("error", reject)
.end();
});
};
let res;
try {
res = await doGet();
} finally {
server.close();
}
expect(res.statusCode).toEqual(200);
});
Environment
When doing a http request with the node.js http client with an object like:
the error in the subject is thrown.
For some reason it does not like the
origin
key. If it is removed the this works as expected.So fix is easy in in userland. In theory. Unfortunately I'm using @elastic/elasticsearch which is creating requests like this internally in some situations and I have no control over it.
Here's a jest test reproducing the error
This crashes with
From debugging the source via
node_modules
the error seems to origin from therequest.url.toString()
call here:https://github.com/mswjs/msw/blob/1562bfc901c930bffc8c5eb150bb855b54020676/src/utils/request/setRequestCookies.ts#L10
Some screenshots from a vscode debug session:
node_modules/msw/node/lib/index.js