Removed unnecessary memmove from chunked response generation. (#188)

This commit is contained in:
Alexandr Zarubkin
2017-08-18 11:54:52 +03:00
committed by Me No Dev
parent 3d0cf89d58
commit 4dcd458d13

View File

@@ -176,7 +176,7 @@ void AsyncBasicResponse::_respond(AsyncWebServerRequest *request){
outLen += _contentLength; outLen += _contentLength;
_writtenLength += request->client()->write(out.c_str(), outLen); _writtenLength += request->client()->write(out.c_str(), outLen);
_state = RESPONSE_WAIT_ACK; _state = RESPONSE_WAIT_ACK;
} else if(space && space < out.length()){ } else if(space && space < outLen){
String partial = out.substring(0, space); String partial = out.substring(0, space);
_content = out.substring(space) + _content; _content = out.substring(space) + _content;
_contentLength += outLen - space; _contentLength += outLen - space;
@@ -284,14 +284,14 @@ size_t AsyncAbstractResponse::_ack(AsyncWebServerRequest *request, size_t len, u
size_t readLen = 0; size_t readLen = 0;
if(_chunked){ if(_chunked){
readLen = _fillBuffer(buf+headLen, outLen - 8); // HTTP 1.1 allows leading zeros in chunk length. Or spaces may be added.
char pre[6]; // See RFC2616 sections 2, 3.6.1.
sprintf(pre, "%x\r\n", readLen); readLen = _fillBuffer(buf+headLen+6, outLen - 8);
size_t preLen = strlen(pre); outLen = sprintf((char*)buf+headLen, "%x", readLen) + headLen;
memmove(buf+headLen+preLen, buf+headLen, readLen); while(outLen < headLen + 4) buf[outLen++] = ' ';
for(size_t i=0; i<preLen; i++) buf[outLen++] = '\r';
buf[i+headLen] = pre[i]; buf[outLen++] = '\n';
outLen = preLen + readLen + headLen; outLen += readLen;
buf[outLen++] = '\r'; buf[outLen++] = '\r';
buf[outLen++] = '\n'; buf[outLen++] = '\n';
} else { } else {