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

Function validateBody

lib/internal/quic/quic.js:1221–1260  ·  view source on GitHub ↗
(body)

Source from the content-addressed store, hash-verified

1219}
1220
1221function validateBody(body) {
1222 if (body === undefined) return body;
1223 // ArrayBuffers, SharedArrayBuffers, and ArrayBufferViews are passed
1224 // through to the C++ layer which copies the bytes into its own
1225 // BackingStore. Callers can therefore safely reuse or mutate their
1226 // input buffers after the call returns. Callers that want to ensure
1227 // their buffer cannot be mutated after handing it off (for example,
1228 // when sharing the source with another async consumer) can call
1229 // ArrayBuffer.prototype.transfer() themselves before passing the
1230 // buffer.
1231 if (isArrayBuffer(body) ||
1232 isSharedArrayBuffer(body) ||
1233 isArrayBufferView(body)) {
1234 return body;
1235 }
1236 if (isBlob(body)) return body[kBlobHandle];
1237
1238 // Strings are encoded as UTF-8.
1239 if (typeof body === 'string') {
1240 return Buffer.from(body, 'utf8');
1241 }
1242
1243 // FileHandle -- lock it and pass the C++ handle to GetDataQueueFromSource
1244 // which creates an fd-backed DataQueue entry from the file path.
1245 if (FileHandle.isFileHandle(body)) {
1246 if (body[kFileLocked]) {
1247 throw new ERR_INVALID_STATE('FileHandle is locked');
1248 }
1249 body[kFileLocked] = true;
1250 return body[kFileHandle];
1251 }
1252
1253 throw new ERR_INVALID_ARG_TYPE('options.body', [
1254 'string',
1255 'ArrayBuffer',
1256 'ArrayBufferView',
1257 'Blob',
1258 'FileHandle',
1259 ], body);
1260}
1261
1262/**
1263 * Parses an alternating [name, value, name, value, ...] array from C++

Callers 3

configureOutboundFunction · 0.85
setOutboundMethod · 0.85
#createStreamMethod · 0.85

Calls 3

isBlobFunction · 0.85
isFileHandleMethod · 0.80
fromMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…