Compare commits

...

7 Commits

Author SHA1 Message Date
cirospaciari
6188bbea8b delay check 2023-12-07 12:05:44 -03:00
cirospaciari
ebd1fcca8b only check for expect once 2023-12-07 12:05:44 -03:00
cirospaciari
6765ac94a7 add another test 2023-12-07 12:05:44 -03:00
cirospaciari
ed505c414c only emit continue when expect: 100-continue 2023-12-07 12:05:44 -03:00
cirospaciari
87ec955173 minimal test 2023-12-07 12:05:44 -03:00
cirospaciari
97d28c514b nextTick is better 2023-12-07 12:05:44 -03:00
cirospaciari
a15a1ff57d workaround 2023-12-07 12:05:44 -03:00
2 changed files with 54 additions and 0 deletions

View File

@@ -1027,6 +1027,11 @@ class OutgoingMessage extends Writable {
}
}
function emitContinueNT(self) {
if (!self._closed && self.getHeader("expect") === "100-continue") {
self.emit("continue");
}
}
function emitCloseNT(self) {
if (!self._closed) {
self.destroyed = true;
@@ -1670,6 +1675,8 @@ class ClientRequest extends OutgoingMessage {
var { signal: _signal, ...optsWithoutSignal } = options;
this.#options = optsWithoutSignal;
process.nextTick(emitContinueNT, this);
}
setSocketKeepAlive(enable = true, initialDelay = 0) {

View File

@@ -1614,3 +1614,50 @@ it("#6892", () => {
expect(req.method).toBeNull();
}
});
// TODO: today we use a workaround to continue event, we need to fix it in the future.
it("should emit continue event #7480", done => {
let receivedContinue = false;
const req = request(
"https://example.com",
{ headers: { "accept-encoding": "identity", "expect": "100-continue" } },
res => {
let data = "";
res.setEncoding("utf8");
res.on("data", chunk => {
data += chunk;
});
res.on("end", () => {
expect(receivedContinue).toBe(true);
expect(data).toContain("This domain is for use in illustrative examples in documents");
done();
});
res.on("error", err => done(err));
},
);
req.on("continue", () => {
receivedContinue = true;
});
req.end();
});
it("should not emit continue event #7480", done => {
let receivedContinue = false;
const req = request("https://example.com", { headers: { "accept-encoding": "identity" } }, res => {
let data = "";
res.setEncoding("utf8");
res.on("data", chunk => {
data += chunk;
});
res.on("end", () => {
expect(receivedContinue).toBe(false);
expect(data).toContain("This domain is for use in illustrative examples in documents");
done();
});
res.on("error", err => done(err));
});
req.on("continue", () => {
receivedContinue = true;
});
req.end();
});