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

Function parseMultipartFormDataHeaders

deps/undici/undici.js:6505–6602  ·  view source on GitHub ↗
(input, position)

Source from the content-addressed store, hash-verified

6503 }
6504 __name(parseContentDispositionAttribute, "parseContentDispositionAttribute");
6505 function parseMultipartFormDataHeaders(input, position) {
6506 let name = null;
6507 let filename = null;
6508 let contentType = null;
6509 let encoding = null;
6510 while (true) {
6511 if (input[position.position] === 13 && input[position.position + 1] === 10) {
6512 if (name === null) {
6513 throw parsingError("header name is null");
6514 }
6515 return { name, filename, contentType, encoding };
6516 }
6517 let headerName = collectASequenceOfBytes(
6518 (char) => char !== 10 && char !== 13 && char !== 58,
6519 input,
6520 position
6521 );
6522 headerName = removeChars(headerName, true, true, (char) => char === 9 || char === 32);
6523 if (!HTTP_TOKEN_CODEPOINTS.test(headerName.toString())) {
6524 throw parsingError("header name does not match the field-name token production");
6525 }
6526 if (input[position.position] !== 58) {
6527 throw parsingError("expected :");
6528 }
6529 position.position++;
6530 collectASequenceOfBytes(
6531 (char) => char === 32 || char === 9,
6532 input,
6533 position
6534 );
6535 switch (bufferToLowerCasedHeaderName(headerName)) {
6536 case "content-disposition": {
6537 name = filename = null;
6538 let filenameIsExtended = false;
6539 const dispositionType = collectASequenceOfBytes(
6540 (char) => isToken(char),
6541 input,
6542 position
6543 );
6544 if (dispositionType.toString("ascii").toLowerCase() !== "form-data") {
6545 throw parsingError("expected form-data for content-disposition header");
6546 }
6547 while (position.position < input.length && (input[position.position] !== 13 || input[position.position + 1] !== 10)) {
6548 const attribute = parseContentDispositionAttribute(input, position);
6549 if (!attribute) {
6550 break;
6551 }
6552 if (attribute.name === "name") {
6553 name = attribute.value;
6554 } else if (attribute.name === "filename") {
6555 if (attribute.extended) {
6556 filename = attribute.value;
6557 filenameIsExtended = true;
6558 } else if (!filenameIsExtended) {
6559 filename = attribute.value;
6560 }
6561 }
6562 }

Callers 1

multipartFormDataParserFunction · 0.70

Calls 9

parsingErrorFunction · 0.70
collectASequenceOfBytesFunction · 0.70
removeCharsFunction · 0.70
isTokenFunction · 0.70
isomorphicDecodeFunction · 0.70
testMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected