Description
I noticed that there's a
void setContentLength(size_t contentLength) { _contentLength = contentLength; }
Its one and only one use is inside the header in 'streamFile' where the contentLength is available already via file.size()
template<typename T> size_t streamFile(T &file, const String& contentType){
if (String(file.name()).endsWith(".gz") &&
contentType != "application/x-gzip" &&
contentType != "application/octet-stream"){
sendHeader("Content-Encoding", "gzip");
}
send(200, contentType, "", file.size());
return _currentClient.write(file, HTTP_DOWNLOAD_UNIT_SIZE);
}
So adding an overloaded send that allows a code/content/body/size which I noticed doesn't exist... except for - send_P which is related to PROGMEM / PGM_P (I could be miss understanding this)
It sorta looks like the _contentLength and supporting code is a kludge around missing a send with this footprint. Which I sorta expected to have, maybe the progmen/pgm_p stuff is more common?
void ESP8266WebServer::send(int code, const char* content_type, char* content, size_t size)
Refactoring this would reduce variable clutter and factor out a state check within_prepareHeader that isn't used for any other functionality and add a function that appears to be missing.
Unless it's there due to backwards compatibility.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.