2424#include " WiFiClient.h"
2525#include " ESP8266WebServer.h"
2626
27- // #define DEBUG
27+ // #define DEBUG_ESP_HTTP_SERVER
28+ #ifdef DEBUG_ESP_PORT
29+ #define DEBUG_OUTPUT DEBUG_ESP_PORT
30+ #else
2831#define DEBUG_OUTPUT Serial
32+ #endif
2933
3034bool ESP8266WebServer::_parseRequest (WiFiClient& client) {
3135 // Read the first line of HTTP request
@@ -41,7 +45,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
4145 int addr_start = req.indexOf (' ' );
4246 int addr_end = req.indexOf (' ' , addr_start + 1 );
4347 if (addr_start == -1 || addr_end == -1 ) {
44- #ifdef DEBUG
48+ #ifdef DEBUG_ESP_HTTP_SERVER
4549 DEBUG_OUTPUT.print (" Invalid request: " );
4650 DEBUG_OUTPUT.println (req);
4751#endif
@@ -72,7 +76,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
7276 }
7377 _currentMethod = method;
7478
75- #ifdef DEBUG
79+ #ifdef DEBUG_ESP_HTTP_SERVER
7680 DEBUG_OUTPUT.print (" method: " );
7781 DEBUG_OUTPUT.print (methodStr);
7882 DEBUG_OUTPUT.print (" url: " );
@@ -111,7 +115,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
111115 headerValue.trim ();
112116 _collectHeader (headerName.c_str (),headerValue.c_str ());
113117
114- #ifdef DEBUG
118+ #ifdef DEBUG_ESP_HTTP_SERVER
115119 DEBUG_OUTPUT.print (" headerName: " );
116120 DEBUG_OUTPUT.println (headerName);
117121 DEBUG_OUTPUT.print (" headerValue: " );
@@ -142,7 +146,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
142146 char *plainBuf = (char *)malloc (plainLen+1 );
143147 client.readBytes (plainBuf, plainLen);
144148 plainBuf[plainLen] = ' \0 ' ;
145- #ifdef DEBUG
149+ #ifdef DEBUG_ESP_HTTP_SERVER
146150 DEBUG_OUTPUT.print (" Plain: " );
147151 DEBUG_OUTPUT.println (plainBuf);
148152#endif
@@ -177,7 +181,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
177181 headerValue = req.substring (headerDiv + 2 );
178182 _collectHeader (headerName.c_str (),headerValue.c_str ());
179183
180- #ifdef DEBUG
184+ #ifdef DEBUG_ESP_HTTP_SERVER
181185 DEBUG_OUTPUT.print (" headerName: " );
182186 DEBUG_OUTPUT.println (headerName);
183187 DEBUG_OUTPUT.print (" headerValue: " );
@@ -192,7 +196,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
192196 }
193197 client.flush ();
194198
195- #ifdef DEBUG
199+ #ifdef DEBUG_ESP_HTTP_SERVER
196200 DEBUG_OUTPUT.print (" Request: " );
197201 DEBUG_OUTPUT.println (url);
198202 DEBUG_OUTPUT.print (" Arguments: " );
@@ -213,7 +217,7 @@ bool ESP8266WebServer::_collectHeader(const char* headerName, const char* header
213217}
214218
215219void ESP8266WebServer::_parseArguments (String data) {
216- #ifdef DEBUG
220+ #ifdef DEBUG_ESP_HTTP_SERVER
217221 DEBUG_OUTPUT.print (" args: " );
218222 DEBUG_OUTPUT.println (data);
219223#endif
@@ -233,7 +237,7 @@ void ESP8266WebServer::_parseArguments(String data) {
233237 ++i;
234238 ++_currentArgCount;
235239 }
236- #ifdef DEBUG
240+ #ifdef DEBUG_ESP_HTTP_SERVER
237241 DEBUG_OUTPUT.print (" args count: " );
238242 DEBUG_OUTPUT.println (_currentArgCount);
239243#endif
@@ -244,7 +248,7 @@ void ESP8266WebServer::_parseArguments(String data) {
244248 for (iarg = 0 ; iarg < _currentArgCount;) {
245249 int equal_sign_index = data.indexOf (' =' , pos);
246250 int next_arg_index = data.indexOf (' &' , pos);
247- #ifdef DEBUG
251+ #ifdef DEBUG_ESP_HTTP_SERVER
248252 DEBUG_OUTPUT.print (" pos " );
249253 DEBUG_OUTPUT.print (pos);
250254 DEBUG_OUTPUT.print (" =@ " );
@@ -253,7 +257,7 @@ void ESP8266WebServer::_parseArguments(String data) {
253257 DEBUG_OUTPUT.println (next_arg_index);
254258#endif
255259 if ((equal_sign_index == -1 ) || ((equal_sign_index > next_arg_index) && (next_arg_index != -1 ))) {
256- #ifdef DEBUG
260+ #ifdef DEBUG_ESP_HTTP_SERVER
257261 DEBUG_OUTPUT.print (" arg missing value: " );
258262 DEBUG_OUTPUT.println (iarg);
259263#endif
@@ -265,7 +269,7 @@ void ESP8266WebServer::_parseArguments(String data) {
265269 RequestArgument& arg = _currentArgs[iarg];
266270 arg.key = data.substring (pos, equal_sign_index);
267271 arg.value = urlDecode (data.substring (equal_sign_index + 1 , next_arg_index));
268- #ifdef DEBUG
272+ #ifdef DEBUG_ESP_HTTP_SERVER
269273 DEBUG_OUTPUT.print (" arg " );
270274 DEBUG_OUTPUT.print (iarg);
271275 DEBUG_OUTPUT.print (" key: " );
@@ -279,7 +283,7 @@ void ESP8266WebServer::_parseArguments(String data) {
279283 pos = next_arg_index + 1 ;
280284 }
281285 _currentArgCount = iarg;
282- #ifdef DEBUG
286+ #ifdef DEBUG_ESP_HTTP_SERVER
283287 DEBUG_OUTPUT.print (" args count: " );
284288 DEBUG_OUTPUT.println (_currentArgCount);
285289#endif
@@ -308,7 +312,7 @@ uint8_t ESP8266WebServer::_uploadReadByte(WiFiClient& client){
308312
309313bool ESP8266WebServer::_parseForm (WiFiClient& client, String boundary, uint32_t len){
310314
311- #ifdef DEBUG
315+ #ifdef DEBUG_ESP_HTTP_SERVER
312316 DEBUG_OUTPUT.print (" Parse Form: Boundary: " );
313317 DEBUG_OUTPUT.print (boundary);
314318 DEBUG_OUTPUT.print (" Length: " );
@@ -346,14 +350,14 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
346350 argFilename = argName.substring (nameStart+2 , argName.length () - 1 );
347351 argName = argName.substring (0 , argName.indexOf (' "' ));
348352 argIsFile = true ;
349- #ifdef DEBUG
353+ #ifdef DEBUG_ESP_HTTP_SERVER
350354 DEBUG_OUTPUT.print (" PostArg FileName: " );
351355 DEBUG_OUTPUT.println (argFilename);
352356#endif
353357 // use GET to set the filename if uploading using blob
354358 if (argFilename == " blob" && hasArg (" filename" )) argFilename = arg (" filename" );
355359 }
356- #ifdef DEBUG
360+ #ifdef DEBUG_ESP_HTTP_SERVER
357361 DEBUG_OUTPUT.print (" PostArg Name: " );
358362 DEBUG_OUTPUT.println (argName);
359363#endif
@@ -366,7 +370,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
366370 client.readStringUntil (' \r ' );
367371 client.readStringUntil (' \n ' );
368372 }
369- #ifdef DEBUG
373+ #ifdef DEBUG_ESP_HTTP_SERVER
370374 DEBUG_OUTPUT.print (" PostArg Type: " );
371375 DEBUG_OUTPUT.println (argType);
372376#endif
@@ -378,7 +382,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
378382 if (argValue.length () > 0 ) argValue += " \n " ;
379383 argValue += line;
380384 }
381- #ifdef DEBUG
385+ #ifdef DEBUG_ESP_HTTP_SERVER
382386 DEBUG_OUTPUT.print (" PostArg Value: " );
383387 DEBUG_OUTPUT.println (argValue);
384388 DEBUG_OUTPUT.println ();
@@ -389,7 +393,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
389393 arg.value = argValue;
390394
391395 if (line == (" --" +boundary+" --" )){
392- #ifdef DEBUG
396+ #ifdef DEBUG_ESP_HTTP_SERVER
393397 DEBUG_OUTPUT.println (" Done Parsing POST" );
394398#endif
395399 break ;
@@ -401,7 +405,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
401405 _currentUpload.type = argType;
402406 _currentUpload.totalSize = 0 ;
403407 _currentUpload.currentSize = 0 ;
404- #ifdef DEBUG
408+ #ifdef DEBUG_ESP_HTTP_SERVER
405409 DEBUG_OUTPUT.print (" Start File: " );
406410 DEBUG_OUTPUT.print (_currentUpload.filename );
407411 DEBUG_OUTPUT.print (" Type: " );
@@ -450,7 +454,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
450454 _currentUpload.status = UPLOAD_FILE_END;
451455 if (_currentHandler && _currentHandler->canUpload (_currentUri))
452456 _currentHandler->upload (*this , _currentUri, _currentUpload);
453- #ifdef DEBUG
457+ #ifdef DEBUG_ESP_HTTP_SERVER
454458 DEBUG_OUTPUT.print (" End File: " );
455459 DEBUG_OUTPUT.print (_currentUpload.filename );
456460 DEBUG_OUTPUT.print (" Type: " );
@@ -461,7 +465,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
461465 line = client.readStringUntil (0x0D );
462466 client.readStringUntil (0x0A );
463467 if (line == " --" ){
464- #ifdef DEBUG
468+ #ifdef DEBUG_ESP_HTTP_SERVER
465469 DEBUG_OUTPUT.println (" Done Parsing POST" );
466470#endif
467471 break ;
@@ -507,7 +511,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
507511 if (postArgs) delete[] postArgs;
508512 return true ;
509513 }
510- #ifdef DEBUG
514+ #ifdef DEBUG_ESP_HTTP_SERVER
511515 DEBUG_OUTPUT.print (" Error: line: " );
512516 DEBUG_OUTPUT.println (line);
513517#endif
0 commit comments