address review

This commit is contained in:
Ciro Spaciari
2025-11-14 15:12:19 -08:00
parent fbee1c8e74
commit 2c719f7d09

View File

@@ -194,6 +194,16 @@ class WrappedSocket extends Duplex {
cb(err);
}
}
async function* getHTTPSocketBody(upgradedPromise: Promise<WrappedSocket | null>) {
const socket = await upgradedPromise;
if (socket) {
const iter = socket[kWrappedSocketWritable]();
for await (const value of iter) {
yield value;
}
}
}
function ClientRequest(input, options, cb) {
if (!(this instanceof ClientRequest)) {
return new (ClientRequest as any)(input, options, cb);
@@ -453,17 +463,9 @@ function ClientRequest(input, options, cb) {
let upgradedResponse: ((socket: WrappedSocket | null) => void) | undefined = undefined;
if (isUpgrade) {
const { promise: upgradedPromise, resolve } = Promise.withResolvers();
const { promise: upgradedPromise, resolve } = Promise.withResolvers<WrappedSocket | null>();
upgradedResponse = resolve;
fetchOptions.body = async function* () {
const socket = await upgradedPromise;
if (socket) {
const iter = socket[kWrappedSocketWritable]();
for await (const value of iter) {
yield value;
}
}
};
fetchOptions.body = getHTTPSocketBody.bind(null, upgradedPromise);
} else if (method !== "GET" && method !== "HEAD" && method !== "OPTIONS") {
const self = this;
if (customBody !== undefined) {