Allow IncomingRequest.req to be overwritten. (#4154)

* Allow IncomingRequest.req to be overwritten.

* add test

* fix test

* yoo
This commit is contained in:
dave caruso
2023-08-17 14:57:43 -07:00
committed by GitHub
parent b2f8ef4dff
commit f74585ff01
3 changed files with 21 additions and 8 deletions

View File

@@ -607,7 +607,7 @@ class IncomingMessage extends Readable {
this.#fakeSocket = socket;
this.url = url.pathname + url.search;
this.#nodeReq = nodeReq;
this.#nodeReq = this.req = nodeReq;
assignHeaders(this, req);
}
@@ -624,10 +624,6 @@ class IncomingMessage extends Readable {
#type;
#nodeReq;
get req() {
return this.#nodeReq;
}
_construct(callback) {
// TODO: streaming
if (this.#type === "response" || this.#noBody) {

File diff suppressed because one or more lines are too long

View File

@@ -733,4 +733,21 @@ describe("node:http", () => {
expect(() => validateHeaderValue("Foo", undefined as any)).toThrow();
expect(() => validateHeaderValue("Foo", "Bar\r")).toThrow();
});
test("req.req = req", done => {
const server = createServer((req, res) => {
req.req = req;
res.write(req.req === req ? "ok" : "fail");
res.end();
});
server.listen({ port: 0 }, async (_err, host, port) => {
try {
const x = await fetch(`http://${host}:${port}`).then(res => res.text());
expect(x).toBe("ok");
done();
} catch (error) {
done(error);
}
});
});
});