MCPcopy Create free account
hub / github.com/nodejs/node / formData

Function formData

deps/undici/src/lib/web/fetch/body.js:340–386  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

338 },
339
340 formData () {
341 // The formData() method steps are to return the result of running
342 // consume body with this and the following step given a byte sequence bytes:
343 return consumeBody(this, (value) => {
344 // 1. Let mimeType be the result of get the MIME type with this.
345 const mimeType = bodyMimeType(getInternalState(this))
346
347 // 2. If mimeType is non-null, then switch on mimeType’s essence and run
348 // the corresponding steps:
349 if (mimeType !== null) {
350 switch (mimeType.essence) {
351 case 'multipart/form-data': {
352 // 1. ... [long step]
353 // 2. If that fails for some reason, then throw a TypeError.
354 const parsed = multipartFormDataParser(value, mimeType)
355
356 // 3. Return a new FormData object, appending each entry,
357 // resulting from the parsing operation, to its entry list.
358 const fd = new FormData()
359 setFormDataState(fd, parsed)
360
361 return fd
362 }
363 case 'application/x-www-form-urlencoded': {
364 // 1. Let entries be the result of parsing bytes.
365 const entries = new URLSearchParams(value.toString())
366
367 // 2. If entries is failure, then throw a TypeError.
368
369 // 3. Return a new FormData object whose entry list is entries.
370 const fd = new FormData()
371
372 for (const [name, value] of entries) {
373 fd.append(name, value)
374 }
375
376 return fd
377 }
378 }
379 }
380
381 // 3. Throw a TypeError.
382 throw new TypeError(
383 'Content-Type was not one of "multipart/form-data" or "application/x-www-form-urlencoded".'
384 )
385 }, instance, getInternalState)
386 },
387
388 bytes () {
389 // The bytes() method steps are to return the result of running consume body

Callers

nothing calls this directly

Calls 5

appendMethod · 0.95
consumeBodyFunction · 0.70
bodyMimeTypeFunction · 0.70
multipartFormDataParserFunction · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected