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

Function extractBody

deps/undici/undici.js:6705–6829  ·  view source on GitHub ↗
(object, keepalive = false)

Source from the content-addressed store, hash-verified

6703 }
6704 });
6705 function extractBody(object, keepalive = false) {
6706 let stream = null;
6707 let controller = null;
6708 if (webidl.is.ReadableStream(object)) {
6709 stream = object;
6710 } else if (webidl.is.Blob(object)) {
6711 stream = object.stream();
6712 } else {
6713 stream = new ReadableStream({
6714 pull() {
6715 },
6716 start(c) {
6717 controller = c;
6718 },
6719 cancel() {
6720 },
6721 type: "bytes"
6722 });
6723 }
6724 assert(webidl.is.ReadableStream(stream));
6725 let action = null;
6726 let source = null;
6727 let length = null;
6728 let type = null;
6729 if (typeof object === "string") {
6730 source = object;
6731 type = "text/plain;charset=UTF-8";
6732 } else if (webidl.is.URLSearchParams(object)) {
6733 source = object.toString();
6734 type = "application/x-www-form-urlencoded;charset=UTF-8";
6735 } else if (webidl.is.BufferSource(object)) {
6736 source = webidl.util.getCopyOfBytesHeldByBufferSource(object);
6737 } else if (webidl.is.FormData(object)) {
6738 const boundary = getFormDataBoundary(object);
6739 const prefix = `--${boundary}\r
6740Content-Disposition: form-data`;
6741 const formdataEscape = /* @__PURE__ */ __name((str) => str.replace(/\n/g, "%0A").replace(/\r/g, "%0D").replace(/"/g, "%22"), "formdataEscape");
6742 const normalizeLinefeeds = /* @__PURE__ */ __name((value) => value.replace(/\r?\n|\r/g, "\r\n"), "normalizeLinefeeds");
6743 const blobParts = [];
6744 const rn = new Uint8Array([13, 10]);
6745 length = 0;
6746 let hasUnknownSizeValue = false;
6747 for (const [name, value] of object) {
6748 if (typeof value === "string") {
6749 const chunk2 = textEncoder.encode(prefix + `; name="${formdataEscape(normalizeLinefeeds(name))}"\r
6750\r
6751${normalizeLinefeeds(value)}\r
6752`);
6753 blobParts.push(chunk2);
6754 length += chunk2.byteLength;
6755 } else {
6756 const chunk2 = textEncoder.encode(`${prefix}; name="${formdataEscape(normalizeLinefeeds(name))}"` + (value.name ? `; filename="${formdataEscape(value.name)}"` : "") + `\r
6757Content-Type: ${value.type || "application/octet-stream"}\r
6758\r
6759`);
6760 blobParts.push(chunk2, value, rn);
6761 if (typeof value.size === "number") {
6762 length += chunk2.byteLength + value.size + rn.byteLength;

Callers 7

safelyExtractBodyFunction · 0.70
writeH1Function · 0.70
writeH2Function · 0.70
jsonMethod · 0.70
constructorMethod · 0.70
constructorMethod · 0.70
schemeFetchFunction · 0.70

Calls 15

__nameFunction · 0.85
formdataEscapeFunction · 0.85
normalizeLinefeedsFunction · 0.85
isUint8ArrayFunction · 0.85
actionFunction · 0.85
isErroredFunction · 0.85
queueMicrotaskFunction · 0.85
BufferSourceMethod · 0.80
encodeMethod · 0.80
ReadableStreamFromFunction · 0.70
readableStreamCloseFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…