@@ -86,6 +86,8 @@ static size_t charactersIndex = 0;
8686static AsyncWebServer server (80 );
8787static AsyncEventSource events (" /events" );
8888
89+ static volatile size_t requests = 0 ;
90+
8991void setup () {
9092 Serial.begin (115200 );
9193
@@ -94,6 +96,26 @@ void setup() {
9496 WiFi.softAP (" esp-captive" );
9597#endif
9698
99+ // Pauses in the request parsing phase
100+ //
101+ // autocannon -c 32 -w 32 -a 96 -t 30 --renderStatusCodes -m POST -H "Content-Type: application/json" -b '{"foo": "bar"}' http://192.168.4.1/delay
102+ //
103+ // curl -v -X POST -H "Content-Type: application/json" -d '{"game": "test"}' http://192.168.4.1/delay
104+ //
105+ server.onNotFound ([](AsyncWebServerRequest *request) {
106+ requests++;
107+ if (request->url () == " /delay" ) {
108+ request->send (200 , " application/json" , " {\" status\" :\" OK\" }" );
109+ } else {
110+ request->send (404 , " text/plain" , " Not found" );
111+ }
112+ });
113+ server.onRequestBody ([](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) {
114+ if (request->url () == " /delay" ) {
115+ delay (3000 );
116+ }
117+ });
118+
97119 // HTTP endpoint
98120 //
99121 // > brew install autocannon
@@ -103,6 +125,7 @@ void setup() {
103125 server.on (" /" , HTTP_GET, [](AsyncWebServerRequest *request) {
104126 // need to cast to uint8_t*
105127 // if you do not, the const char* will be copied in a temporary String buffer
128+ requests++;
106129 request->send (200 , " text/html" , (uint8_t *)htmlContent, htmlContentLength);
107130 });
108131
@@ -120,6 +143,7 @@ void setup() {
120143 // time curl -N -v -G -d 'd=2000' -d 'l=10000' http://192.168.4.1/slow.html --output -
121144 //
122145 server.on (" /slow.html" , HTTP_GET, [](AsyncWebServerRequest *request) {
146+ requests++;
123147 uint32_t d = request->getParam (" d" )->value ().toInt ();
124148 uint32_t l = request->getParam (" l" )->value ().toInt ();
125149 Serial.printf (" d = %" PRIu32 " , l = %" PRIu32 " \n " , d, l);
@@ -212,7 +236,7 @@ void loop() {
212236
213237#ifdef ESP32
214238 if (now - lastHeap >= 2000 ) {
215- Serial.printf (" Free heap: %" PRIu32 " \n " , ESP.getFreeHeap ());
239+ Serial.printf (" Uptime: %3lu s, requests: %3u, Free heap: %" PRIu32 " \n " , millis () / 1000 , requests , ESP.getFreeHeap ());
216240 lastHeap = now;
217241 }
218242#endif
0 commit comments