Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit ca11d5d

Browse files
authored
Add files via upload
1 parent 1bd70ec commit ca11d5d

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

src/Portenta_H7_AsyncWebResponseImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class AsyncBasicResponse: public AsyncWebServerResponse
4444
private:
4545
String _content;
4646
char *_contentCstr; // RSMOD
47+
String _partialHeader;
4748

4849
public:
4950
AsyncBasicResponse(int code, const String& contentType = String(), const String& content = String());

src/Portenta_H7_AsyncWebResponses.cpp

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ AsyncBasicResponse::AsyncBasicResponse(int code, const String& contentType, cons
259259
_content = String("");
260260
_contentCstr = (char *)content; // RSMOD
261261
_contentType = contentType;
262+
_partialHeader = String();
262263

263264
int iLen;
264265

@@ -284,6 +285,7 @@ AsyncBasicResponse::AsyncBasicResponse(int code, const String& contentType, cons
284285
_content = content;
285286
_contentCstr = nullptr; // RSMOD
286287
_contentType = contentType;
288+
_partialHeader = String();
287289

288290
if (_content.length())
289291
{
@@ -319,22 +321,26 @@ void AsyncBasicResponse::_respond(AsyncWebServerRequest *request)
319321
{
320322
AWS_LOGDEBUG("Step 2");
321323

324+
322325
if (_contentCstr)
323326
{
327+
/*
324328
memmove(&_contentCstr[outLen], _contentCstr, _contentLength);
325329
memcpy(_contentCstr, out.c_str(), outLen);
326330
outLen += _contentLength;
327331
328332
AWS_LOGDEBUG1("_contentCstr =", _contentCstr);
329333
330334
_writtenLength += request->client()->write(_contentCstr, outLen);
335+
*/
336+
_content = String(_contentCstr); // short _contentCstr - so just send as Arduino String - not much of a penalty - fall into below
331337
}
332-
else
333-
{
338+
//else
339+
//{
334340
out += _content;
335341
outLen += _contentLength;
336342
_writtenLength += request->client()->write(out.c_str(), outLen);
337-
}
343+
//}
338344

339345
_state = RESPONSE_WAIT_ACK;
340346
}
@@ -346,18 +352,19 @@ void AsyncBasicResponse::_respond(AsyncWebServerRequest *request)
346352

347353
if (_contentCstr)
348354
{
349-
int deltaLen = out.length() - partial.length();
355+
//int deltaLen = out.length() - partial.length();
356+
357+
_partialHeader = out.substring(space);
350358

351-
memmove(&_contentCstr[deltaLen], _contentCstr, deltaLen);
352-
memcpy(_contentCstr, out.substring(space).c_str(), deltaLen);
359+
//memmove(&_contentCstr[deltaLen], _contentCstr, deltaLen);
360+
//memcpy(_contentCstr, out.substring(space).c_str(), deltaLen);
353361
}
354362
else
355363
{
356364
_content = out.substring(space) + _content;
365+
_contentLength += outLen - space;
357366
}
358367

359-
_contentLength += outLen - space;
360-
361368
AWS_LOGDEBUG1("partial =", partial);
362369

363370
_writtenLength += request->client()->write(partial.c_str(), partial.length());
@@ -400,15 +407,15 @@ void AsyncBasicResponse::_respond(AsyncWebServerRequest *request)
400407

401408
if (_contentCstr)
402409
{
403-
memmove(&_contentCstr[outLen], _contentCstr, _contentLength);
404-
memcpy(_contentCstr, out.c_str(), outLen);
410+
_partialHeader = out;
411+
//memmove(&_contentCstr[outLen], _contentCstr, _contentLength);
412+
//memcpy(_contentCstr, out.c_str(), outLen);
405413
}
406414
else
407415
{
408416
_content = out + _content;
417+
_contentLength += outLen;
409418
}
410-
411-
_contentLength += outLen;
412419
_state = RESPONSE_CONTENT;
413420
}
414421

@@ -431,6 +438,31 @@ size_t AsyncBasicResponse::_ack(AsyncWebServerRequest *request, size_t len, uint
431438
String out;
432439
size_t available = _contentLength - _sentLength;
433440
size_t space = request->client()->space();
441+
442+
if (_partialHeader.length() > 0) {
443+
if (_partialHeader.length() > space) {
444+
// Header longer than space - send a piece of it, and make the _partialHeader = to what remains
445+
String _subHeader;
446+
String tmpString;
447+
448+
_subHeader = _partialHeader.substring(0, space);
449+
tmpString = _partialHeader.substring(space);
450+
_partialHeader = tmpString;
451+
452+
_writtenLength += request->client()->write(_subHeader.c_str(), space);
453+
454+
return(_partialHeader.length());
455+
} else {
456+
// _partialHeader is <= space length - therefore send the whole thing, and make the remaining length = to the _contrentLength
457+
_writtenLength += request->client()->write(_partialHeader.c_str(), _partialHeader.length());
458+
459+
_partialHeader = String();
460+
461+
return(_contentLength);
462+
}
463+
}
464+
465+
// if we are here - there is no _partialHJeader to send
434466

435467
AWS_LOGDEBUG3("AsyncAbstractResponse::_ack : available =", available, ", space =", space );
436468

0 commit comments

Comments
 (0)