MCPcopy Create free account
hub / github.com/Heltec-Aaron-Lee/WiFi_Kit_series / _parseForm

Method _parseForm

libraries/WebServer/src/Parsing.cpp:412–593  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

410}
411
412bool WebServer::_parseForm(NetworkClient &client, const String &boundary, uint32_t len) {
413 (void)len;
414 log_v("Parse Form: Boundary: %s Length: %" PRIu32, boundary.c_str(), len);
415 String line;
416 int retry = 0;
417 do {
418 line = client.readStringUntil('\r');
419 ++retry;
420 } while (line.length() == 0 && retry < 3);
421
422 client.readStringUntil('\n');
423 //start reading the form
424 if (line == ("--" + boundary)) {
425 if (_postArgs) {
426 delete[] _postArgs;
427 }
428 _postArgs = new RequestArgument[WEBSERVER_MAX_POST_ARGS];
429 _postArgsLen = 0;
430 while (1) {
431 String argName;
432 String argValue;
433 String argType;
434 String argFilename;
435 bool argIsFile = false;
436
437 line = client.readStringUntil('\r');
438 client.readStringUntil('\n');
439 if (line.length() > (size_t)19 && line.substring(0, 19).equalsIgnoreCase(F("Content-Disposition"))) {
440 int nameStart = line.indexOf('=');
441 if (nameStart != -1) {
442 argName = line.substring(nameStart + 2);
443 nameStart = argName.indexOf('=');
444 if (nameStart == -1) {
445 argName = argName.substring(0, argName.length() - 1);
446 } else {
447 argFilename = argName.substring(nameStart + 2, argName.length() - 1);
448 argName = argName.substring(0, argName.indexOf('"'));
449 argIsFile = true;
450 log_v("PostArg FileName: %s", argFilename.c_str());
451 //use GET to set the filename if uploading using blob
452 if (argFilename == F("blob") && hasArg(FPSTR(filename))) {
453 argFilename = arg(FPSTR(filename));
454 }
455 }
456 log_v("PostArg Name: %s", argName.c_str());
457 using namespace mime;
458 argType = FPSTR(mimeTable[txt].mimeType);
459 line = client.readStringUntil('\r');
460 client.readStringUntil('\n');
461 while (line.length() > 0) {
462 if (line.length() > (size_t)12 && line.substring(0, 12).equalsIgnoreCase(FPSTR(Content_Type))) {
463 argType = line.substring(line.indexOf(':') + 2);
464 }
465 //skip over any other headers
466 line = client.readStringUntil('\r');
467 client.readStringUntil('\n');
468 }
469 log_v("PostArg Type: %s", argType.c_str());

Callers

nothing calls this directly

Calls 11

c_strMethod · 0.80
equalsIgnoreCaseMethod · 0.80
indexOfMethod · 0.80
readStringUntilMethod · 0.45
lengthMethod · 0.45
substringMethod · 0.45
startsWithMethod · 0.45
resetMethod · 0.45
canUploadMethod · 0.45
uploadMethod · 0.45
connectedMethod · 0.45

Tested by

no test coverage detected