MCPcopy Create free account
hub / github.com/nodejs/undici / gettingDecodingSplitting

Function gettingDecodingSplitting

lib/web/fetch/util.js:1355–1415  ·  view source on GitHub ↗

* @see https://fetch.spec.whatwg.org/#header-value-get-decode-and-split * @param {string|null} value

(value)

Source from the content-addressed store, hash-verified

1353 * @param {string|null} value
1354 */
1355function gettingDecodingSplitting (value) {
1356 // 1. Let input be the result of isomorphic decoding value.
1357 const input = value
1358
1359 // 2. Let position be a position variable for input, initially pointing at the start of input.
1360 const position = { position: 0 }
1361
1362 // 3. Let values be a list of strings, initially empty.
1363 const values = []
1364
1365 // 4. Let temporaryValue be the empty string.
1366 let temporaryValue = ''
1367
1368 // 5. While position is not past the end of input:
1369 while (position.position < input.length) {
1370 // 5.1. Append the result of collecting a sequence of code points that are not U+0022 (")
1371 // or U+002C (,) from input, given position, to temporaryValue.
1372 temporaryValue += collectASequenceOfCodePoints(
1373 (char) => char !== '"' && char !== ',',
1374 input,
1375 position
1376 )
1377
1378 // 5.2. If position is not past the end of input, then:
1379 if (position.position < input.length) {
1380 // 5.2.1. If the code point at position within input is U+0022 ("), then:
1381 if (input.charCodeAt(position.position) === 0x22) {
1382 // 5.2.1.1. Append the result of collecting an HTTP quoted string from input, given position, to temporaryValue.
1383 temporaryValue += collectAnHTTPQuotedString(
1384 input,
1385 position
1386 )
1387
1388 // 5.2.1.2. If position is not past the end of input, then continue.
1389 if (position.position < input.length) {
1390 continue
1391 }
1392 } else {
1393 // 5.2.2. Otherwise:
1394
1395 // 5.2.2.1. Assert: the code point at position within input is U+002C (,).
1396 assert(input.charCodeAt(position.position) === 0x2C)
1397
1398 // 5.2.2.2. Advance position by 1.
1399 position.position++
1400 }
1401 }
1402
1403 // 5.3. Remove all HTTP tab or space from the start and end of temporaryValue.
1404 temporaryValue = removeChars(temporaryValue, true, true, (char) => char === 0x9 || char === 0x20)
1405
1406 // 5.4. Append temporaryValue to values.
1407 values.push(temporaryValue)
1408
1409 // 5.6. Set temporaryValue to the empty string.
1410 temporaryValue = ''
1411 }
1412

Callers 1

getDecodeSplitFunction · 0.85

Calls 4

removeCharsFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected