Skip to content
9 changes: 7 additions & 2 deletions libraries/ESP8266WebServer/src/ESP8266WebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,15 @@ class ESP8266WebServerTemplate

static String urlDecode(const String& text);

// send file based header and stream body when not "HTTP_HEAD"
template<typename T>
size_t streamFile(T &file, const String& contentType) {
size_t streamFile(T &file, const String& contentType, HTTPMethod requestMethod = HTTP_GET) {
_streamFileCore(file.size(), file.name(), contentType);
return _currentClient.write(file);
if (requestMethod != HTTP_HEAD) {
return _currentClient.write(file);
} else {
return 0;
}
}

static const String responseCodeToString(const int code);
Expand Down
4 changes: 2 additions & 2 deletions libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class StaticRequestHandler : public RequestHandler<ServerType> {
}

bool canHandle(HTTPMethod requestMethod, String requestUri) override {
if (requestMethod != HTTP_GET)
if ((requestMethod != HTTP_GET) && (requestMethod != HTTP_HEAD))
return false;

if ((_isFile && requestUri != _uri) || !requestUri.startsWith(_uri))
Expand Down Expand Up @@ -125,7 +125,7 @@ class StaticRequestHandler : public RequestHandler<ServerType> {
if (_cache_header.length() != 0)
server.sendHeader("Cache-Control", _cache_header);

server.streamFile(f, contentType);
server.streamFile(f, contentType, requestMethod);
return true;
}

Expand Down