@@ -214,12 +214,22 @@ void ESP8266WebServer::_uploadWriteByte(uint8_t b){
214
214
_currentUpload.buf [_currentUpload.currentSize ++] = b;
215
215
}
216
216
217
+ uint8_t ESP8266WebServer::_uploadReadByte (WiFiClient& client){
218
+ int res = client.read ();
219
+ if (res == -1 ){
220
+ while (!client.available ())
221
+ yield ();
222
+ res = client.read ();
223
+ }
224
+ return (uint8_t )res;
225
+ }
226
+
217
227
void ESP8266WebServer::_parseForm (WiFiClient& client, String boundary, uint32_t len){
218
228
219
229
#ifdef DEBUG
220
230
DEBUG_OUTPUT.print (" Parse Form: Boundary: " );
221
231
DEBUG_OUTPUT.print (boundary);
222
- DEBUG_OUTPUT.print (" Length: " );
232
+ DEBUG_OUTPUT.print (" Length: " );
223
233
DEBUG_OUTPUT.println (len);
224
234
#endif
225
235
String line;
@@ -249,17 +259,17 @@ void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
249
259
argFilename = argName.substring (nameStart+2 , argName.length () - 1 );
250
260
argName = argName.substring (0 , argName.indexOf (' "' ));
251
261
argIsFile = true ;
252
- #ifdef DEBUG
262
+ #ifdef DEBUG
253
263
DEBUG_OUTPUT.print (" PostArg FileName: " );
254
264
DEBUG_OUTPUT.println (argFilename);
255
- #endif
265
+ #endif
256
266
// use GET to set the filename if uploading using blob
257
267
if (argFilename == " blob" && hasArg (" filename" )) argFilename = arg (" filename" );
258
268
}
259
- #ifdef DEBUG
269
+ #ifdef DEBUG
260
270
DEBUG_OUTPUT.print (" PostArg Name: " );
261
271
DEBUG_OUTPUT.println (argName);
262
- #endif
272
+ #endif
263
273
argType = " text/plain" ;
264
274
line = client.readStringUntil (' \r ' );
265
275
client.readStringUntil (' \n ' );
@@ -269,10 +279,10 @@ void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
269
279
client.readStringUntil (' \r ' );
270
280
client.readStringUntil (' \n ' );
271
281
}
272
- #ifdef DEBUG
282
+ #ifdef DEBUG
273
283
DEBUG_OUTPUT.print (" PostArg Type: " );
274
284
DEBUG_OUTPUT.println (argType);
275
- #endif
285
+ #endif
276
286
if (!argIsFile){
277
287
while (1 ){
278
288
line = client.readStringUntil (' \r ' );
@@ -281,20 +291,20 @@ void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
281
291
if (argValue.length () > 0 ) argValue += " \n " ;
282
292
argValue += line;
283
293
}
284
- #ifdef DEBUG
294
+ #ifdef DEBUG
285
295
DEBUG_OUTPUT.print (" PostArg Value: " );
286
296
DEBUG_OUTPUT.println (argValue);
287
297
DEBUG_OUTPUT.println ();
288
- #endif
298
+ #endif
289
299
290
300
RequestArgument& arg = postArgs[postArgsLen++];
291
301
arg.key = argName;
292
302
arg.value = argValue;
293
303
294
304
if (line == (" --" +boundary+" --" )){
295
- #ifdef DEBUG
305
+ #ifdef DEBUG
296
306
DEBUG_OUTPUT.println (" Done Parsing POST" );
297
- #endif
307
+ #endif
298
308
break ;
299
309
}
300
310
} else {
@@ -312,23 +322,23 @@ void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
312
322
#endif
313
323
if (_fileUploadHandler) _fileUploadHandler ();
314
324
_currentUpload.status = UPLOAD_FILE_WRITE;
315
- uint8_t argByte = client. read ( );
325
+ uint8_t argByte = _uploadReadByte (client );
316
326
readfile:
317
327
while (argByte != 0x0D ){
318
328
_uploadWriteByte (argByte);
319
- argByte = client. read ( );
329
+ argByte = _uploadReadByte (client );
320
330
}
321
331
322
- argByte = client. read ( );
332
+ argByte = _uploadReadByte (client );
323
333
if (argByte == 0x0A ){
324
- argByte = client. read ( );
334
+ argByte = _uploadReadByte (client );
325
335
if ((char )argByte != ' -' ){
326
336
// continue reading the file
327
337
_uploadWriteByte (0x0D );
328
338
_uploadWriteByte (0x0A );
329
339
goto readfile;
330
340
} else {
331
- argByte = client. read ( );
341
+ argByte = _uploadReadByte (client );
332
342
if ((char )argByte != ' -' ){
333
343
// continue reading the file
334
344
_uploadWriteByte (0x0D );
@@ -366,11 +376,13 @@ void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
366
376
} else {
367
377
_uploadWriteByte (0x0D );
368
378
_uploadWriteByte (0x0A );
379
+ _uploadWriteByte ((uint8_t )(' -' ));
380
+ _uploadWriteByte ((uint8_t )(' -' ));
369
381
uint32_t i = 0 ;
370
382
while (i < boundary.length ()){
371
383
_uploadWriteByte (endBuf[i++]);
372
384
}
373
- argByte = client. read ( );
385
+ argByte = _uploadReadByte (client );
374
386
goto readfile;
375
387
}
376
388
} else {
0 commit comments