From 7de29c46a70d86ffeecdc9fc10e6c2d6cb04f392 Mon Sep 17 00:00:00 2001 From: Anatole SCHRAMM Date: Thu, 3 Nov 2022 13:04:06 +0100 Subject: [PATCH] Finished to add the cookietest api endpoint which purpose is to test the cookie handling feature of the WEBServer --- src/app/webApi.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/app/webApi.cpp b/src/app/webApi.cpp index 57462b2..5233283 100644 --- a/src/app/webApi.cpp +++ b/src/app/webApi.cpp @@ -670,26 +670,30 @@ boolean cookieTestApi(WEBServer *ws, WEBServer::HttpReques if(HRD.getParams("set") != NULL) { uint8_t cookieCount(HRD.getParams.count() - 1); - Serial.printf("Cookies to be set/unset : %u\n", cookieCount); + for(uint8_t i(0); i < HRD.getParams.count(); i++) { if(strcmp(HRD.getParams.getParameter(i), "set") != 0) { if(!strlen(HRD.getParams.getAt(i)->getString())) //We ask to remove the cookie - { - Serial.printf("Unsetting cookie %s->%s\n", HRD.getParams.getParameter(i), HRD.getParams.getAt(i)->getString()); ws->addCookies(HRD.getParams.getParameter(i), HRD.getParams.getAt(i)->getString(), 0); - } else //We add the cookie - { - Serial.printf("Setting cookie %s->%s\n", HRD.getParams.getParameter(i), HRD.getParams.getAt(i)->getString()); ws->addCookies(HRD.getParams.getParameter(i), HRD.getParams.getAt(i)->getString(), 3600); - } } } ws->sendHTTPResponse(wc, HttpConstants::httpMIMETypeToString(HttpConstants::TEXT_PLAIN)); //We dont know the content length wc->printf("Setting/Unsetting %u cookies : \n", cookieCount); + for(uint8_t i(0); i < HRD.getParams.count(); i++) + { + if(strcmp(HRD.getParams.getParameter(i), "set") != 0) + { + if(!strlen(HRD.getParams.getAt(i)->getString())) //We ask to remove the cookie + wc->printf("Unsetting cookie %s->%s\n", HRD.getParams.getParameter(i), HRD.getParams.getAt(i)->getString()); + else //We add the cookie + wc->printf("Setting cookie %s->%s\n", HRD.getParams.getParameter(i), HRD.getParams.getAt(i)->getString()); + } + } } else //We print the setted cookies {