{"version":3,"file":"body.mjs","sources":["../../../../lib/web/fetch/body.js"],"sourcesContent":["'use strict'\n\nconst util = require('../../core/util')\nconst {\n  ReadableStreamFrom,\n  readableStreamClose,\n  fullyReadBody,\n  extractMimeType\n} = require('./util')\nconst { FormData, setFormDataState, getFormDataBoundary } = require('./formdata')\nconst { webidl } = require('../webidl')\nconst assert = require('node:assert')\nconst { isErrored, isDisturbed } = require('node:stream')\nconst { isUint8Array } = require('node:util/types')\nconst { serializeAMimeType } = require('./data-url')\nconst { multipartFormDataParser } = require('./formdata-parser')\nconst { parseJSONFromBytes } = require('../infra')\nconst { utf8DecodeBytes } = require('../../encoding')\nconst { ReadableStreamTee } = require('node:stream/web')\n\nconst textEncoder = new TextEncoder()\nfunction noop () {}\n\nconst streamRegistry = new FinalizationRegistry((weakRef) => {\n  const stream = weakRef.deref()\n  if (stream && !stream.locked && !isDisturbed(stream) && !isErrored(stream)) {\n    stream.cancel('Response object has been garbage collected').catch(noop)\n  }\n})\n\n/**\n * Extract a body with type from a byte sequence or BodyInit object\n *\n * @param {import('../../../types').BodyInit} object - The BodyInit object to extract from\n * @param {boolean} [keepalive=false] - If true, indicates that the body\n * @returns {[{stream: ReadableStream, source: any, length: number | null}, string | null]} - Returns a tuple containing the body and its type\n *\n * @see https://fetch.spec.whatwg.org/#concept-bodyinit-extract\n */\nfunction extractBody (object, keepalive = false) {\n  // 1. Let stream be null.\n  let stream = null\n  let controller = null\n\n  // 2. If object is a ReadableStream object, then set stream to object.\n  if (webidl.is.ReadableStream(object)) {\n    stream = object\n  } else if (webidl.is.Blob(object)) {\n    // 3. Otherwise, if object is a Blob object, set stream to the\n    //    result of running object’s get stream.\n    stream = object.stream()\n  } else {\n    // 4. Otherwise, set stream to a new ReadableStream object, and set\n    //    up stream with byte reading support.\n    stream = new ReadableStream({\n      pull () {},\n      start (c) {\n        controller = c\n      },\n      cancel () {},\n      type: 'bytes'\n    })\n  }\n\n  // 5. Assert: stream is a ReadableStream object.\n  assert(webidl.is.ReadableStream(stream))\n\n  // 6. Let action be null.\n  let action = null\n\n  // 7. Let source be null.\n  let source = null\n\n  // 8. Let length be null.\n  let length = null\n\n  // 9. Let type be null.\n  let type = null\n\n  // 10. Switch on object:\n  if (typeof object === 'string') {\n    // Set source to the UTF-8 encoding of object.\n    // Note: setting source to a Uint8Array here breaks some mocking assumptions.\n    source = object\n\n    // Set type to `text/plain;charset=UTF-8`.\n    type = 'text/plain;charset=UTF-8'\n  } else if (webidl.is.URLSearchParams(object)) {\n    // URLSearchParams\n\n    // spec says to run application/x-www-form-urlencoded on body.list\n    // this is implemented in Node.js as apart of an URLSearchParams instance toString method\n    // See: https://github.com/nodejs/node/blob/e46c680bf2b211bbd52cf959ca17ee98c7f657f5/lib/internal/url.js#L490\n    // and https://github.com/nodejs/node/blob/e46c680bf2b211bbd52cf959ca17ee98c7f657f5/lib/internal/url.js#L1100\n\n    // Set source to the result of running the application/x-www-form-urlencoded serializer with object’s list.\n    source = object.toString()\n\n    // Set type to `application/x-www-form-urlencoded;charset=UTF-8`.\n    type = 'application/x-www-form-urlencoded;charset=UTF-8'\n  } else if (webidl.is.BufferSource(object)) {\n    // Set source to a copy of the bytes held by object.\n    source = webidl.util.getCopyOfBytesHeldByBufferSource(object)\n  } else if (webidl.is.FormData(object)) {\n    const boundary = getFormDataBoundary(object)\n    const prefix = `--${boundary}\\r\\nContent-Disposition: form-data`\n\n    /*! formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */\n    const formdataEscape = (str) =>\n      str.replace(/\\n/g, '%0A').replace(/\\r/g, '%0D').replace(/\"/g, '%22')\n    const normalizeLinefeeds = (value) => value.replace(/\\r?\\n|\\r/g, '\\r\\n')\n\n    // Set action to this step: run the multipart/form-data\n    // encoding algorithm, with object’s entry list and UTF-8.\n    // - This ensures that the body is immutable and can't be changed afterwords\n    // - That the content-length is calculated in advance.\n    // - And that all parts are pre-encoded and ready to be sent.\n\n    const blobParts = []\n    const rn = new Uint8Array([13, 10]) // '\\r\\n'\n    length = 0\n    let hasUnknownSizeValue = false\n\n    for (const [name, value] of object) {\n      if (typeof value === 'string') {\n        const chunk = textEncoder.encode(prefix +\n          `; name=\"${formdataEscape(normalizeLinefeeds(name))}\"` +\n          `\\r\\n\\r\\n${normalizeLinefeeds(value)}\\r\\n`)\n        blobParts.push(chunk)\n        length += chunk.byteLength\n      } else {\n        const chunk = textEncoder.encode(`${prefix}; name=\"${formdataEscape(normalizeLinefeeds(name))}\"` +\n          (value.name ? `; filename=\"${formdataEscape(value.name)}\"` : '') + '\\r\\n' +\n          `Content-Type: ${\n            value.type || 'application/octet-stream'\n          }\\r\\n\\r\\n`)\n        blobParts.push(chunk, value, rn)\n        if (typeof value.size === 'number') {\n          length += chunk.byteLength + value.size + rn.byteLength\n        } else {\n          hasUnknownSizeValue = true\n        }\n      }\n    }\n\n    // CRLF is appended to the body to function with legacy servers and match other implementations.\n    // https://github.com/curl/curl/blob/3434c6b46e682452973972e8313613dfa58cd690/lib/mime.c#L1029-L1030\n    // https://github.com/form-data/form-data/issues/63\n    const chunk = textEncoder.encode(`--${boundary}--\\r\\n`)\n    blobParts.push(chunk)\n    length += chunk.byteLength\n    if (hasUnknownSizeValue) {\n      length = null\n    }\n\n    // Set source to object.\n    source = object\n\n    action = async function * () {\n      for (const part of blobParts) {\n        if (part.stream) {\n          yield * part.stream()\n        } else {\n          yield part\n        }\n      }\n    }\n\n    // Set type to `multipart/form-data; boundary=`,\n    // followed by the multipart/form-data boundary string generated\n    // by the multipart/form-data encoding algorithm.\n    type = `multipart/form-data; boundary=${boundary}`\n  } else if (webidl.is.Blob(object)) {\n    // Blob\n\n    // Set source to object.\n    source = object\n\n    // Set length to object’s size.\n    length = object.size\n\n    // If object’s type attribute is not the empty byte sequence, set\n    // type to its value.\n    if (object.type) {\n      type = object.type\n    }\n  } else if (typeof object[Symbol.asyncIterator] === 'function') {\n    // If keepalive is true, then throw a TypeError.\n    if (keepalive) {\n      throw new TypeError('keepalive')\n    }\n\n    // If object is disturbed or locked, then throw a TypeError.\n    if (util.isDisturbed(object) || object.locked) {\n      throw new TypeError(\n        'Response body object should not be disturbed or locked'\n      )\n    }\n\n    stream =\n      webidl.is.ReadableStream(object) ? object : ReadableStreamFrom(object)\n  }\n\n  // 11. If source is a byte sequence, then set action to a\n  // step that returns source and length to source’s length.\n  if (typeof source === 'string' || isUint8Array(source)) {\n    action = () => {\n      length = typeof source === 'string' ? Buffer.byteLength(source) : source.length\n      return source\n    }\n  }\n\n  // 12. If action is non-null, then run these steps in parallel:\n  if (action != null) {\n    ;(async () => {\n      // 1. Run action.\n      const result = action()\n\n      // 2. Whenever one or more bytes are available and stream is not errored,\n      //    enqueue the result of creating a Uint8Array from the available bytes into stream.\n      const iterator = result?.[Symbol.asyncIterator]?.()\n      if (iterator) {\n        for await (const bytes of iterator) {\n          if (isErrored(stream)) break\n          if (bytes.length) {\n            controller.enqueue(new Uint8Array(bytes))\n          }\n        }\n      } else if (result?.length && !isErrored(stream)) {\n        controller.enqueue(typeof result === 'string' ? textEncoder.encode(result) : new Uint8Array(result))\n      }\n\n      // 3. When running action is done, close stream.\n      queueMicrotask(() => readableStreamClose(controller))\n    })()\n  }\n\n  // 13. Let body be a body whose stream is stream, source is source,\n  // and length is length.\n  const body = { stream, source, length }\n\n  // 14. Return (body, type).\n  return [body, type]\n}\n\n/**\n * @typedef {object} ExtractBodyResult\n * @property {ReadableStream<Uint8Array<ArrayBuffer>>} stream - The ReadableStream containing the body data\n * @property {any} source - The original source of the body data\n * @property {number | null} length - The length of the body data, or null\n */\n\n/**\n * Safely extract a body with type from a byte sequence or BodyInit object.\n *\n * @param {import('../../../types').BodyInit} object - The BodyInit object to extract from\n * @param {boolean} [keepalive=false] - If true, indicates that the body\n * @returns {[ExtractBodyResult, string | null]} - Returns a tuple containing the body and its type\n *\n * @see https://fetch.spec.whatwg.org/#bodyinit-safely-extract\n */\nfunction safelyExtractBody (object, keepalive = false) {\n  // To safely extract a body and a `Content-Type` value from\n  // a byte sequence or BodyInit object object, run these steps:\n\n  // 1. If object is a ReadableStream object, then:\n  if (webidl.is.ReadableStream(object)) {\n    // Assert: object is neither disturbed nor locked.\n    assert(!util.isDisturbed(object), 'The body has already been consumed.')\n    assert(!object.locked, 'The stream is locked.')\n  }\n\n  // 2. Return the results of extracting object.\n  return extractBody(object, keepalive)\n}\n\nfunction cloneBody (body) {\n  // To clone a body body, run these steps:\n\n  // https://fetch.spec.whatwg.org/#concept-body-clone\n\n  // 1. Let « out1, out2 » be the result of teeing body’s stream.\n  const { 0: out1, 1: out2 } = ReadableStreamTee?.(body.stream, true) ?? body.stream.tee()\n\n  // 2. Set body’s stream to out1.\n  body.stream = out1\n\n  // 3. Return a body whose stream is out2 and other members are copied from body.\n  return {\n    stream: out2,\n    length: body.length,\n    source: body.source\n  }\n}\n\nfunction bodyMixinMethods (instance, getInternalState) {\n  const methods = {\n    blob () {\n      // The blob() method steps are to return the result of\n      // running consume body with this and the following step\n      // given a byte sequence bytes: return a Blob whose\n      // contents are bytes and whose type attribute is this’s\n      // MIME type.\n      return consumeBody(this, (bytes) => {\n        let mimeType = bodyMimeType(getInternalState(this))\n\n        if (mimeType === null) {\n          mimeType = ''\n        } else if (mimeType) {\n          mimeType = serializeAMimeType(mimeType)\n        }\n\n        // Return a Blob whose contents are bytes and type attribute\n        // is mimeType.\n        return new Blob([bytes], { type: mimeType })\n      }, instance, getInternalState)\n    },\n\n    arrayBuffer () {\n      // The arrayBuffer() method steps are to return the result\n      // of running consume body with this and the following step\n      // given a byte sequence bytes: return a new ArrayBuffer\n      // whose contents are bytes.\n      return consumeBody(this, (bytes) => {\n        return new Uint8Array(bytes).buffer\n      }, instance, getInternalState)\n    },\n\n    text () {\n      // The text() method steps are to return the result of running\n      // consume body with this and UTF-8 decode.\n      return consumeBody(this, utf8DecodeBytes, instance, getInternalState)\n    },\n\n    json () {\n      // The json() method steps are to return the result of running\n      // consume body with this and parse JSON from bytes.\n      return consumeBody(this, parseJSONFromBytes, instance, getInternalState)\n    },\n\n    formData () {\n      // The formData() method steps are to return the result of running\n      // consume body with this and the following step given a byte sequence bytes:\n      return consumeBody(this, (value) => {\n        // 1. Let mimeType be the result of get the MIME type with this.\n        const mimeType = bodyMimeType(getInternalState(this))\n\n        // 2. If mimeType is non-null, then switch on mimeType’s essence and run\n        //    the corresponding steps:\n        if (mimeType !== null) {\n          switch (mimeType.essence) {\n            case 'multipart/form-data': {\n              // 1. ... [long step]\n              // 2. If that fails for some reason, then throw a TypeError.\n              const parsed = multipartFormDataParser(value, mimeType)\n\n              // 3. Return a new FormData object, appending each entry,\n              //    resulting from the parsing operation, to its entry list.\n              const fd = new FormData()\n              setFormDataState(fd, parsed)\n\n              return fd\n            }\n            case 'application/x-www-form-urlencoded': {\n              // 1. Let entries be the result of parsing bytes.\n              const entries = new URLSearchParams(value.toString())\n\n              // 2. If entries is failure, then throw a TypeError.\n\n              // 3. Return a new FormData object whose entry list is entries.\n              const fd = new FormData()\n\n              for (const [name, value] of entries) {\n                fd.append(name, value)\n              }\n\n              return fd\n            }\n          }\n        }\n\n        // 3. Throw a TypeError.\n        throw new TypeError(\n          'Content-Type was not one of \"multipart/form-data\" or \"application/x-www-form-urlencoded\".'\n        )\n      }, instance, getInternalState)\n    },\n\n    bytes () {\n      // The bytes() method steps are to return the result of running consume body\n      // with this and the following step given a byte sequence bytes: return the\n      // result of creating a Uint8Array from bytes in this’s relevant realm.\n      return consumeBody(this, (bytes) => {\n        return new Uint8Array(bytes)\n      }, instance, getInternalState)\n    },\n\n    textStream () {\n      const this_ = getInternalState(this)\n\n      // 1. If this is unusable, then throw a TypeError.\n      if (bodyUnusable(this_)) {\n        throw new TypeError('Body is unusable: Body has already been read')\n      }\n\n      // 2. If this’s body is null:\n      if (this_.body == null) {\n        // 2.1. Let emptyStream be a new ReadableStream in this’s relevant realm.\n        // 2.2. Set up emptyStream.\n        /** @type {ReadableStreamDefaultController<any>} */\n        let controller\n        const emptyStream = new ReadableStream({\n          start: (c) => {\n            controller = c\n          },\n          pull: () => Promise.resolve(),\n          cancel: () => Promise.resolve()\n        }, {\n          size: () => 1\n        })\n\n        // 2.3. Close emptyStream.\n        controller.close()\n\n        // 2.4. Return emptyStream.\n        return emptyStream\n      }\n\n      // 3. Let stream be this’s body’s stream.\n      /** @type {ReadableStream} */\n      const stream = this_.body.stream\n\n      // 4. Let decoder be a new TextDecoderStream object in this’s relevant realm.\n      // 5. Set up decoder with UTF-8.\n      const decoder = new TextDecoderStream('UTF-8')\n\n      // 6. Return the result of stream, piped through decoder.\n      return stream.pipeThrough(decoder)\n    }\n  }\n\n  return methods\n}\n\nfunction mixinBody (prototype, getInternalState) {\n  Object.assign(prototype.prototype, bodyMixinMethods(prototype, getInternalState))\n}\n\n/**\n * @see https://fetch.spec.whatwg.org/#concept-body-consume-body\n * @param {any} object internal state\n * @param {(value: unknown) => unknown} convertBytesToJSValue\n * @param {any} instance\n * @param {(target: any) => any} getInternalState\n */\nfunction consumeBody (object, convertBytesToJSValue, instance, getInternalState) {\n  try {\n    webidl.brandCheck(object, instance)\n  } catch (e) {\n    return Promise.reject(e)\n  }\n\n  object = getInternalState(object)\n\n  // 1. If object is unusable, then return a promise rejected\n  //    with a TypeError.\n  if (bodyUnusable(object)) {\n    return Promise.reject(new TypeError('Body is unusable: Body has already been read'))\n  }\n\n  // 2. Let promise be a new promise.\n  const promise = Promise.withResolvers()\n\n  // 3. Let errorSteps given error be to reject promise with error.\n  const errorSteps = promise.reject\n\n  // 4. Let successSteps given a byte sequence data be to resolve\n  //    promise with the result of running convertBytesToJSValue\n  //    with data. If that threw an exception, then run errorSteps\n  //    with that exception.\n  const successSteps = (data) => {\n    try {\n      promise.resolve(convertBytesToJSValue(data))\n    } catch (e) {\n      errorSteps(e)\n    }\n  }\n\n  // 5. If object’s body is null, then run successSteps with an\n  //    empty byte sequence.\n  if (object.body == null) {\n    successSteps(Buffer.allocUnsafe(0))\n    return promise.promise\n  }\n\n  // 6. Otherwise, fully read object’s body given successSteps,\n  //    errorSteps, and object’s relevant global object.\n  fullyReadBody(object.body, successSteps, errorSteps)\n\n  // 7. Return promise.\n  return promise.promise\n}\n\n/**\n * @see https://fetch.spec.whatwg.org/#body-unusable\n * @param {any} object internal state\n */\nfunction bodyUnusable (object) {\n  const body = object.body\n\n  // An object including the Body interface mixin is\n  // said to be unusable if its body is non-null and\n  // its body’s stream is disturbed or locked.\n  return body != null && (body.stream.locked || util.isDisturbed(body.stream))\n}\n\n/**\n * @see https://fetch.spec.whatwg.org/#concept-body-mime-type\n * @param {any} requestOrResponse internal state\n */\nfunction bodyMimeType (requestOrResponse) {\n  // 1. Let headers be null.\n  // 2. If requestOrResponse is a Request object, then set headers to requestOrResponse’s request’s header list.\n  // 3. Otherwise, set headers to requestOrResponse’s response’s header list.\n  /** @type {import('./headers').HeadersList} */\n  const headers = requestOrResponse.headersList\n\n  // 4. Let mimeType be the result of extracting a MIME type from headers.\n  const mimeType = extractMimeType(headers)\n\n  // 5. If mimeType is failure, then return null.\n  if (mimeType === 'failure') {\n    return null\n  }\n\n  // 6. Return mimeType.\n  return mimeType\n}\n\nmodule.exports = {\n  extractBody,\n  safelyExtractBody,\n  cloneBody,\n  mixinBody,\n  streamRegistry,\n  bodyUnusable\n}\n"],"names":["util","require$$0","ReadableStreamFrom","readableStreamClose","fullyReadBody","extractMimeType","require$$1","FormData","setFormDataState","getFormDataBoundary","require$$2","webidl","require$$3","assert","require$$4","isErrored","isDisturbed","require$$5","isUint8Array","require$$6","serializeAMimeType","require$$7","multipartFormDataParser","require$$8","parseJSONFromBytes","require$$9","utf8DecodeBytes","require$$10","ReadableStreamTee","require$$11","textEncoder","TextEncoder","noop","streamRegistry","FinalizationRegistry","weakRef","stream","deref","locked","cancel","catch","extractBody","object","keepalive","controller","is","ReadableStream","Blob","pull","start","c","type","action","source","length","URLSearchParams","toString","BufferSource","getCopyOfBytesHeldByBufferSource","boundary","prefix","formdataEscape","str","replace","normalizeLinefeeds","value","blobParts","rn","Uint8Array","hasUnknownSizeValue","name","chunk","encode","push","byteLength","size","async","part","Symbol","asyncIterator","TypeError","Buffer","result","iterator","bytes","enqueue","queueMicrotask","consumeBody","convertBytesToJSValue","instance","getInternalState","brandCheck","e","Promise","reject","bodyUnusable","promise","withResolvers","errorSteps","successSteps","data","resolve","body","allocUnsafe","bodyMimeType","requestOrResponse","headers","headersList","mimeType","safelyExtractBody","cloneBody","out1","out2","tee","mixinBody","prototype","Object","assign","blob","this","arrayBuffer","buffer","text","json","formData","essence","parsed","fd","entries","append","textStream","this_","emptyStream","close","decoder","TextDecoderStream","pipeThrough","bodyMixinMethods"],"mappings":"mxBAEA,MAAMA,OAAOC,MACPC,mBACcC,oBACCC,cACNC,iBAEXC,eACEC,SAAUC,iBAAkBC,qBAA0BC,mBACtDC,QAAaC,gBACbC,OAASC,YACTC,UAAWC,aAAkBC,YAC7BC,cAAmBC,YACnBC,oBAAyBC,kBACzBC,yBAA8BC,yBAC9BC,oBAAyBC,gBACzBC,iBAAsBC,mBACtBC,mBAAwBC,IAExBC,YAAc,IAAIC,YACxB,SAASC,OAAQ,CAEjB,MAAMC,eAAiB,IAAIC,qBAAsBC,UAC/C,MAAMC,OAASD,QAAQE,SACnBD,QAAWA,OAAOE,QAAWtB,YAAYoB,SAAYrB,UAAUqB,SACjEA,OAAOG,OAAO,8CAA8CC,MAAMR;;;;;;;;;IAatE,SAASS,YAAaC,OAAQC,WAAY;;AAExC,IAAIP,OAAS,KACTQ,WAAa;;AAIfR,OADEzB,OAAOkC,GAAGC,eAAeJ,QAClBA,OACA/B,OAAOkC,GAAGE,KAAKL,QAGfA,OAAON,SAIP,IAAIU,eAAe,CAC1B,IAAAE,GAAQ,EACR,KAAAC,CAAOC,GACLN,WAAaM,CACrB,EACM,MAAAX,GAAU,EACVY,KAAM;;AAKVtC,OAAOF,OAAOkC,GAAGC,eAAeV;;AAGhC,IAAIgB,OAAS,KAGTC,OAAS,KAGTC,OAAS,KAGTH,KAAO;;;AAGX,GAAsB,iBAAXT;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