ESP8266WebServer::client() should return a reference · Issue #7075 · esp8266/Arduino (original) (raw)
Hi,
Currently ESP8266WebServer::client()
returns a WiFiClient
by value, which forbids passing the result directly to a function taking a Client&
.
For example, it causes a compilation error with ArduinoJson:
serializeJson(doc, server.client());
Because serializeJson() takes a Print&
, the line above produces the following error:
no instance of overloaded function "serializeJson" matches the argument list -- argument types are: (ArduinoJson6141_0000010::StaticJsonDocument<768U>, WiFiServer::ClientType)
To fix this problem, ESP8266WebServer::client()
must return a reference (and not a copy), just as HTTPClient::getStream()
does.
(see also this question on StackOverflow)
Best regards,
Benoit