mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Allow IncomingRequest.req to be overwritten. (#4154)
* Allow IncomingRequest.req to be overwritten. * add test * fix test * yoo
This commit is contained in:
@@ -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
@@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user