24
24
#include " WiFiClient.h"
25
25
#include " ESP8266WebServer.h"
26
26
27
- // #define DEBUG
27
+ // #define DEBUG_ESP_HTTP_SERVER
28
+ #ifdef DEBUG_ESP_PORT
29
+ #define DEBUG_OUTPUT DEBUG_ESP_PORT
30
+ #else
28
31
#define DEBUG_OUTPUT Serial
32
+ #endif
29
33
30
34
bool ESP8266WebServer::_parseRequest (WiFiClient& client) {
31
35
// Read the first line of HTTP request
@@ -41,7 +45,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
41
45
int addr_start = req.indexOf (' ' );
42
46
int addr_end = req.indexOf (' ' , addr_start + 1 );
43
47
if (addr_start == -1 || addr_end == -1 ) {
44
- #ifdef DEBUG
48
+ #ifdef DEBUG_ESP_HTTP_SERVER
45
49
DEBUG_OUTPUT.print (" Invalid request: " );
46
50
DEBUG_OUTPUT.println (req);
47
51
#endif
@@ -72,7 +76,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
72
76
}
73
77
_currentMethod = method;
74
78
75
- #ifdef DEBUG
79
+ #ifdef DEBUG_ESP_HTTP_SERVER
76
80
DEBUG_OUTPUT.print (" method: " );
77
81
DEBUG_OUTPUT.print (methodStr);
78
82
DEBUG_OUTPUT.print (" url: " );
@@ -111,7 +115,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
111
115
headerValue.trim ();
112
116
_collectHeader (headerName.c_str (),headerValue.c_str ());
113
117
114
- #ifdef DEBUG
118
+ #ifdef DEBUG_ESP_HTTP_SERVER
115
119
DEBUG_OUTPUT.print (" headerName: " );
116
120
DEBUG_OUTPUT.println (headerName);
117
121
DEBUG_OUTPUT.print (" headerValue: " );
@@ -142,7 +146,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
142
146
char *plainBuf = (char *)malloc (plainLen+1 );
143
147
client.readBytes (plainBuf, plainLen);
144
148
plainBuf[plainLen] = ' \0 ' ;
145
- #ifdef DEBUG
149
+ #ifdef DEBUG_ESP_HTTP_SERVER
146
150
DEBUG_OUTPUT.print (" Plain: " );
147
151
DEBUG_OUTPUT.println (plainBuf);
148
152
#endif
@@ -177,7 +181,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
177
181
headerValue = req.substring (headerDiv + 2 );
178
182
_collectHeader (headerName.c_str (),headerValue.c_str ());
179
183
180
- #ifdef DEBUG
184
+ #ifdef DEBUG_ESP_HTTP_SERVER
181
185
DEBUG_OUTPUT.print (" headerName: " );
182
186
DEBUG_OUTPUT.println (headerName);
183
187
DEBUG_OUTPUT.print (" headerValue: " );
@@ -192,7 +196,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
192
196
}
193
197
client.flush ();
194
198
195
- #ifdef DEBUG
199
+ #ifdef DEBUG_ESP_HTTP_SERVER
196
200
DEBUG_OUTPUT.print (" Request: " );
197
201
DEBUG_OUTPUT.println (url);
198
202
DEBUG_OUTPUT.print (" Arguments: " );
@@ -213,7 +217,7 @@ bool ESP8266WebServer::_collectHeader(const char* headerName, const char* header
213
217
}
214
218
215
219
void ESP8266WebServer::_parseArguments (String data) {
216
- #ifdef DEBUG
220
+ #ifdef DEBUG_ESP_HTTP_SERVER
217
221
DEBUG_OUTPUT.print (" args: " );
218
222
DEBUG_OUTPUT.println (data);
219
223
#endif
@@ -233,7 +237,7 @@ void ESP8266WebServer::_parseArguments(String data) {
233
237
++i;
234
238
++_currentArgCount;
235
239
}
236
- #ifdef DEBUG
240
+ #ifdef DEBUG_ESP_HTTP_SERVER
237
241
DEBUG_OUTPUT.print (" args count: " );
238
242
DEBUG_OUTPUT.println (_currentArgCount);
239
243
#endif
@@ -244,7 +248,7 @@ void ESP8266WebServer::_parseArguments(String data) {
244
248
for (iarg = 0 ; iarg < _currentArgCount;) {
245
249
int equal_sign_index = data.indexOf (' =' , pos);
246
250
int next_arg_index = data.indexOf (' &' , pos);
247
- #ifdef DEBUG
251
+ #ifdef DEBUG_ESP_HTTP_SERVER
248
252
DEBUG_OUTPUT.print (" pos " );
249
253
DEBUG_OUTPUT.print (pos);
250
254
DEBUG_OUTPUT.print (" =@ " );
@@ -253,7 +257,7 @@ void ESP8266WebServer::_parseArguments(String data) {
253
257
DEBUG_OUTPUT.println (next_arg_index);
254
258
#endif
255
259
if ((equal_sign_index == -1 ) || ((equal_sign_index > next_arg_index) && (next_arg_index != -1 ))) {
256
- #ifdef DEBUG
260
+ #ifdef DEBUG_ESP_HTTP_SERVER
257
261
DEBUG_OUTPUT.print (" arg missing value: " );
258
262
DEBUG_OUTPUT.println (iarg);
259
263
#endif
@@ -265,7 +269,7 @@ void ESP8266WebServer::_parseArguments(String data) {
265
269
RequestArgument& arg = _currentArgs[iarg];
266
270
arg.key = data.substring (pos, equal_sign_index);
267
271
arg.value = urlDecode (data.substring (equal_sign_index + 1 , next_arg_index));
268
- #ifdef DEBUG
272
+ #ifdef DEBUG_ESP_HTTP_SERVER
269
273
DEBUG_OUTPUT.print (" arg " );
270
274
DEBUG_OUTPUT.print (iarg);
271
275
DEBUG_OUTPUT.print (" key: " );
@@ -279,7 +283,7 @@ void ESP8266WebServer::_parseArguments(String data) {
279
283
pos = next_arg_index + 1 ;
280
284
}
281
285
_currentArgCount = iarg;
282
- #ifdef DEBUG
286
+ #ifdef DEBUG_ESP_HTTP_SERVER
283
287
DEBUG_OUTPUT.print (" args count: " );
284
288
DEBUG_OUTPUT.println (_currentArgCount);
285
289
#endif
@@ -308,7 +312,7 @@ uint8_t ESP8266WebServer::_uploadReadByte(WiFiClient& client){
308
312
309
313
bool ESP8266WebServer::_parseForm (WiFiClient& client, String boundary, uint32_t len){
310
314
311
- #ifdef DEBUG
315
+ #ifdef DEBUG_ESP_HTTP_SERVER
312
316
DEBUG_OUTPUT.print (" Parse Form: Boundary: " );
313
317
DEBUG_OUTPUT.print (boundary);
314
318
DEBUG_OUTPUT.print (" Length: " );
@@ -346,14 +350,14 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
346
350
argFilename = argName.substring (nameStart+2 , argName.length () - 1 );
347
351
argName = argName.substring (0 , argName.indexOf (' "' ));
348
352
argIsFile = true ;
349
- #ifdef DEBUG
353
+ #ifdef DEBUG_ESP_HTTP_SERVER
350
354
DEBUG_OUTPUT.print (" PostArg FileName: " );
351
355
DEBUG_OUTPUT.println (argFilename);
352
356
#endif
353
357
// use GET to set the filename if uploading using blob
354
358
if (argFilename == " blob" && hasArg (" filename" )) argFilename = arg (" filename" );
355
359
}
356
- #ifdef DEBUG
360
+ #ifdef DEBUG_ESP_HTTP_SERVER
357
361
DEBUG_OUTPUT.print (" PostArg Name: " );
358
362
DEBUG_OUTPUT.println (argName);
359
363
#endif
@@ -366,7 +370,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
366
370
client.readStringUntil (' \r ' );
367
371
client.readStringUntil (' \n ' );
368
372
}
369
- #ifdef DEBUG
373
+ #ifdef DEBUG_ESP_HTTP_SERVER
370
374
DEBUG_OUTPUT.print (" PostArg Type: " );
371
375
DEBUG_OUTPUT.println (argType);
372
376
#endif
@@ -378,7 +382,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
378
382
if (argValue.length () > 0 ) argValue += " \n " ;
379
383
argValue += line;
380
384
}
381
- #ifdef DEBUG
385
+ #ifdef DEBUG_ESP_HTTP_SERVER
382
386
DEBUG_OUTPUT.print (" PostArg Value: " );
383
387
DEBUG_OUTPUT.println (argValue);
384
388
DEBUG_OUTPUT.println ();
@@ -389,7 +393,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
389
393
arg.value = argValue;
390
394
391
395
if (line == (" --" +boundary+" --" )){
392
- #ifdef DEBUG
396
+ #ifdef DEBUG_ESP_HTTP_SERVER
393
397
DEBUG_OUTPUT.println (" Done Parsing POST" );
394
398
#endif
395
399
break ;
@@ -401,7 +405,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
401
405
_currentUpload.type = argType;
402
406
_currentUpload.totalSize = 0 ;
403
407
_currentUpload.currentSize = 0 ;
404
- #ifdef DEBUG
408
+ #ifdef DEBUG_ESP_HTTP_SERVER
405
409
DEBUG_OUTPUT.print (" Start File: " );
406
410
DEBUG_OUTPUT.print (_currentUpload.filename );
407
411
DEBUG_OUTPUT.print (" Type: " );
@@ -450,7 +454,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
450
454
_currentUpload.status = UPLOAD_FILE_END;
451
455
if (_currentHandler && _currentHandler->canUpload (_currentUri))
452
456
_currentHandler->upload (*this , _currentUri, _currentUpload);
453
- #ifdef DEBUG
457
+ #ifdef DEBUG_ESP_HTTP_SERVER
454
458
DEBUG_OUTPUT.print (" End File: " );
455
459
DEBUG_OUTPUT.print (_currentUpload.filename );
456
460
DEBUG_OUTPUT.print (" Type: " );
@@ -461,7 +465,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
461
465
line = client.readStringUntil (0x0D );
462
466
client.readStringUntil (0x0A );
463
467
if (line == " --" ){
464
- #ifdef DEBUG
468
+ #ifdef DEBUG_ESP_HTTP_SERVER
465
469
DEBUG_OUTPUT.println (" Done Parsing POST" );
466
470
#endif
467
471
break ;
@@ -507,7 +511,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
507
511
if (postArgs) delete[] postArgs;
508
512
return true ;
509
513
}
510
- #ifdef DEBUG
514
+ #ifdef DEBUG_ESP_HTTP_SERVER
511
515
DEBUG_OUTPUT.print (" Error: line: " );
512
516
DEBUG_OUTPUT.println (line);
513
517
#endif
0 commit comments