me-no-dev / ESPAsyncWebServer

Async Web Server for ESP8266 and ESP32
3.7k stars 1.21k forks source link

Request disable sending Content-Length: 0 on HEAD #1393

Open DRSDavidSoft opened 5 months ago

DRSDavidSoft commented 5 months ago

I would prefer to do something like this:

if (request->method() == HTTP_HEAD)
{
    response = request->beginResponse(200, "application/octet-stream", "");
    response->setContentLength(0);
    response->setSendContentLength(false); // ?????
    response->addHeader("Content-Length", String(FinalDataSize));
}

Instead, I have to do this:

if (request->method() == HTTP_HEAD)
{
    response = request->beginResponse(200, "application/octet-stream", "");
    response->setContentLength(0);
    response->addHeader("Content-Length", String(FinalDataSize));
}

Which is bad, because it sends the Content-Length twice, once with the incorrect value of 0 and once with the correct Data size. Notice, in the HEAD request we must specify the data's correct Content-Length but MUST NOT send any content whatsover.

If I do response->setContentLength(15); for example, then ESPAsyncWebServer will send 15 bytes of unknown memory to the client which is obviously invalid.

DRSDavidSoft commented 3 weeks ago

This issue has been solved in mathieucarbou's fork:

I'm using that fork now.