@@ -193,7 +193,7 @@ void ESP8266WebServer::handleClient() {
193
193
_currentStatus = HC_NONE;
194
194
return ;
195
195
}
196
-
196
+ _currentClient. setTimeout (HTTP_MAX_SEND_WAIT);
197
197
_contentLength = CONTENT_LENGTH_NOT_SET;
198
198
_handleRequest ();
199
199
@@ -241,6 +241,9 @@ void ESP8266WebServer::sendHeader(const String& name, const String& value, bool
241
241
}
242
242
}
243
243
244
+ void ESP8266WebServer::setContentLength (size_t contentLength) {
245
+ _contentLength = contentLength;
246
+ }
244
247
245
248
void ESP8266WebServer::_prepareHeader (String& response, int code, const char * content_type, size_t contentLength) {
246
249
response = " HTTP/1.1 " ;
@@ -270,7 +273,6 @@ void ESP8266WebServer::send(int code, const char* content_type, const String& co
270
273
String header;
271
274
_prepareHeader (header, code, content_type, content.length ());
272
275
sendContent (header);
273
-
274
276
sendContent (content);
275
277
}
276
278
@@ -307,67 +309,15 @@ void ESP8266WebServer::send(int code, const String& content_type, const String&
307
309
}
308
310
309
311
void ESP8266WebServer::sendContent (const String& content) {
310
- const size_t unit_size = HTTP_DOWNLOAD_UNIT_SIZE;
311
- size_t size_to_send = content.length ();
312
- const char * send_start = content.c_str ();
313
-
314
- while (size_to_send) {
315
- size_t will_send = (size_to_send < unit_size) ? size_to_send : unit_size;
316
- size_t sent = _currentClient.write (send_start, will_send);
317
- if (sent == 0 ) {
318
- break ;
319
- }
320
- size_to_send -= sent;
321
- send_start += sent;
322
- }
312
+ _currentClient.write (content.c_str (), content.length ());
323
313
}
324
314
325
315
void ESP8266WebServer::sendContent_P (PGM_P content) {
326
- char contentUnit[HTTP_DOWNLOAD_UNIT_SIZE + 1 ];
327
-
328
- contentUnit[HTTP_DOWNLOAD_UNIT_SIZE] = ' \0 ' ;
329
-
330
- while (content != NULL ) {
331
- size_t contentUnitLen;
332
- PGM_P contentNext;
333
-
334
- // due to the memccpy signature, lots of casts are needed
335
- contentNext = (PGM_P)memccpy_P ((void *)contentUnit, (PGM_VOID_P)content, 0 , HTTP_DOWNLOAD_UNIT_SIZE);
336
-
337
- if (contentNext == NULL ) {
338
- // no terminator, more data available
339
- content += HTTP_DOWNLOAD_UNIT_SIZE;
340
- contentUnitLen = HTTP_DOWNLOAD_UNIT_SIZE;
341
- }
342
- else {
343
- // reached terminator. Do not send the terminator
344
- contentUnitLen = contentNext - contentUnit - 1 ;
345
- content = NULL ;
346
- }
347
-
348
- // write is so overloaded, had to use the cast to get it pick the right one
349
- _currentClient.write ((const char *)contentUnit, contentUnitLen);
350
- }
316
+ _currentClient.write_P (content, strlen_P (content));
351
317
}
352
318
353
319
void ESP8266WebServer::sendContent_P (PGM_P content, size_t size) {
354
- char contentUnit[HTTP_DOWNLOAD_UNIT_SIZE + 1 ];
355
- contentUnit[HTTP_DOWNLOAD_UNIT_SIZE] = ' \0 ' ;
356
- size_t remaining_size = size;
357
-
358
- while (content != NULL && remaining_size > 0 ) {
359
- size_t contentUnitLen = HTTP_DOWNLOAD_UNIT_SIZE;
360
-
361
- if (remaining_size < HTTP_DOWNLOAD_UNIT_SIZE) contentUnitLen = remaining_size;
362
- // due to the memcpy signature, lots of casts are needed
363
- memcpy_P ((void *)contentUnit, (PGM_VOID_P)content, contentUnitLen);
364
-
365
- content += contentUnitLen;
366
- remaining_size -= contentUnitLen;
367
-
368
- // write is so overloaded, had to use the cast to get it pick the right one
369
- _currentClient.write ((const char *)contentUnit, contentUnitLen);
370
- }
320
+ _currentClient.write_P (content, size);
371
321
}
372
322
373
323
0 commit comments