in packages/dubbo-node/src/node-universal-client.ts [196:257]
body: h2ResponseIterable(sentinel, stream, sessionManager),
trailer: h2ResponseTrailer(stream),
};
resolve(response);
});
}
);
});
};
}
function h1Request(
sentinel: Sentinel,
url: string,
options:
| Omit<http.RequestOptions, "signal">
| Omit<https.RequestOptions, "signal">,
onRequest: (request: http.ClientRequest) => void
): void {
let request: http.ClientRequest;
if (new URL(url).protocol.startsWith("https")) {
request = https.request(url, options);
} else {
request = http.request(url, options);
}
sentinel.catch((reason) =>
request.destroy(connectErrorFromNodeReason(reason))
);
// Node.js will only send headers with the first request body byte by default.
// We force it to send headers right away for consistent behavior between
// HTTP/1.1 and HTTP/2.2 clients.
request.flushHeaders();
request.on("error", sentinel.reject);
request.on("socket", function onRequestSocket(socket: net.Socket) {
function onSocketConnect() {
socket.off("connect", onSocketConnect);
onRequest(request);
}
// If readyState is open, then socket is already open due to keepAlive, so
// the 'connect' event will never fire so call onRequest explicitly
if (socket.readyState === "open") {
onRequest(request);
} else {
socket.on("connect", onSocketConnect);
}
});
}
function h1ResponseIterable(
sentinel: Sentinel,
response: http.IncomingMessage,
trailer: Headers
): AsyncIterable<Uint8Array> {
const inner: AsyncIterator<Uint8Array> = response[Symbol.asyncIterator]();
return {
[Symbol.asyncIterator]() {
return {
async next(): Promise<IteratorResult<Uint8Array>> {
const r = await sentinel.race(inner.next());
if (r.done === true) {