MCPcopy Index your code
hub / github.com/nodejs/node / configureOutbound

Function configureOutbound

lib/internal/quic/quic.js:1328–1403  ·  view source on GitHub ↗
(handle, stream, body)

Source from the content-addressed store, hash-verified

1326const kDefaultMaxPendingDatagrams = 128;
1327
1328function configureOutbound(handle, stream, body) {
1329 // body: null - close writable side immediately (FIN)
1330 if (body === null) {
1331 handle.initStreamingSource();
1332 handle.endWrite();
1333 return;
1334 }
1335
1336 // Handle Promise - await and recurse. Native promises auto-flatten,
1337 // so the resolved value will never itself be a promise.
1338 if (isPromise(body)) {
1339 PromisePrototypeThen(
1340 body,
1341 (resolved) => configureOutbound(handle, stream, resolved),
1342 (err) => {
1343 if (!stream.destroyed) {
1344 stream.destroy(err);
1345 }
1346 },
1347 );
1348 return;
1349 }
1350
1351 // Tier: One-shot - string (checked before sync iterable since
1352 // strings are iterable but we want the one-shot path).
1353 // Buffer.from may return a pooled buffer whose ArrayBuffer cannot
1354 // be transferred, so run it through validateBody which copies when
1355 // the buffer is a partial view of a larger ArrayBuffer.
1356 if (typeof body === 'string') {
1357 handle.attachSource(validateBody(Buffer.from(body, 'utf8')));
1358 return;
1359 }
1360
1361 // Tier: One-shot - FileHandle. The C++ layer creates an fd-backed
1362 // DataQueue entry from the file path. The FileHandle is locked to
1363 // prevent concurrent use and closed automatically when the stream
1364 // finishes.
1365 if (FileHandle.isFileHandle(body)) {
1366 if (body[kFileLocked]) {
1367 throw new ERR_INVALID_STATE('FileHandle is locked');
1368 }
1369 body[kFileLocked] = true;
1370 handle.attachSource(body[kFileHandle]);
1371 return;
1372 }
1373
1374 // Tier: One-shot - ArrayBuffer, SharedArrayBuffer, TypedArray,
1375 // DataView, Blob. validateBody handles transfer-vs-copy logic,
1376 // SharedArrayBuffer copying, and partial view safety.
1377 if (isArrayBuffer(body) || isSharedArrayBuffer(body) ||
1378 isArrayBufferView(body) || isBlob(body)) {
1379 handle.attachSource(validateBody(body));
1380 return;
1381 }
1382
1383 // Tier: Streaming - AsyncIterable (ReadableStream, stream.Readable,
1384 // async generators, etc.). Checked before sync iterable because some
1385 // objects implement both protocols and we prefer async.

Callers 1

setBodyMethod · 0.85

Calls 9

validateBodyFunction · 0.85
isBlobFunction · 0.85
consumeAsyncSourceFunction · 0.85
consumeSyncSourceFunction · 0.85
isFileHandleMethod · 0.80
isAsyncIterableFunction · 0.70
isSyncIterableFunction · 0.70
destroyMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…