Skip to content

Commit 70c3370

Browse files
jennytood-a-v
authored andcommitted
Fix sending headers in #send_P(int, PGM_P, PGM_P, size_t) (#6881)
The method #send(int, char*, char*[, size_t])) is a virtual method which calculates the size of the content then calls #send_P(int, PGM_P, PGM_P, size_t). This particular implementation of #send_P differs from the other implementations of #send and #send_P in that it uses #sendContent for headers and always calls #sendContent_P for contents even when the contents is not specified. The method #sendContent is intended for body and prepends the chunksize in chunk mode but this breaks the HTTP protocol which does not expect a chunksize prior to the headers. Fix is simply to do the same thing as all the other methods - call _currentClient.write and only call #sendContent_P if there is content to send.
1 parent 759ba27 commit 70c3370

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

libraries/ESP8266WebServer/src/ESP8266WebServer-impl.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,10 @@ void ESP8266WebServerTemplate<ServerType>::send_P(int code, PGM_P content_type,
464464
char type[64];
465465
memccpy_P((void*)type, (PGM_VOID_P)content_type, 0, sizeof(type));
466466
_prepareHeader(header, code, (const char* )type, contentLength);
467-
sendContent(header);
468-
sendContent_P(content, contentLength);
467+
_currentClient.write((const uint8_t *)header.c_str(), header.length());
468+
if (contentLength) {
469+
sendContent_P(content, contentLength);
470+
}
469471
}
470472

471473
template <typename ServerType>

0 commit comments

Comments
 (0)