@@ -86,6 +86,8 @@ static size_t charactersIndex = 0;
86
86
static AsyncWebServer server (80 );
87
87
static AsyncEventSource events (" /events" );
88
88
89
+ static volatile size_t requests = 0 ;
90
+
89
91
void setup () {
90
92
Serial.begin (115200 );
91
93
@@ -94,6 +96,26 @@ void setup() {
94
96
WiFi.softAP (" esp-captive" );
95
97
#endif
96
98
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
+
97
119
// HTTP endpoint
98
120
//
99
121
// > brew install autocannon
@@ -103,6 +125,7 @@ void setup() {
103
125
server.on (" /" , HTTP_GET, [](AsyncWebServerRequest *request) {
104
126
// need to cast to uint8_t*
105
127
// if you do not, the const char* will be copied in a temporary String buffer
128
+ requests++;
106
129
request->send (200 , " text/html" , (uint8_t *)htmlContent, htmlContentLength);
107
130
});
108
131
@@ -120,6 +143,7 @@ void setup() {
120
143
// time curl -N -v -G -d 'd=2000' -d 'l=10000' http://192.168.4.1/slow.html --output -
121
144
//
122
145
server.on (" /slow.html" , HTTP_GET, [](AsyncWebServerRequest *request) {
146
+ requests++;
123
147
uint32_t d = request->getParam (" d" )->value ().toInt ();
124
148
uint32_t l = request->getParam (" l" )->value ().toInt ();
125
149
Serial.printf (" d = %" PRIu32 " , l = %" PRIu32 " \n " , d, l);
@@ -212,7 +236,7 @@ void loop() {
212
236
213
237
#ifdef ESP32
214
238
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 ());
216
240
lastHeap = now;
217
241
}
218
242
#endif
0 commit comments