You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ESP8266WebServer::client() should return a reference #7075
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.
Looks like this is a popular request. At first glance, though, it looks like a breaking API change. Would you like to do a PR with the change and see if it breaks any of the existing examples, @bblanchon ? Seems like it would be a simple tweak...
If it does end up breaking things, then it probably need to be pushed to 3.0. If not, might make it into 2.7...
@earlephilhower , I opened #7080 .
I don't think it should break anything: since WiFiClient is copy-constructible, a copy will be implicitly created if needed.
Activity
earlephilhower commentedon Feb 12, 2020
Looks like this is a popular request. At first glance, though, it looks like a breaking API change. Would you like to do a PR with the change and see if it breaks any of the existing examples, @bblanchon ? Seems like it would be a simple tweak...
If it does end up breaking things, then it probably need to be pushed to 3.0. If not, might make it into 2.7...
Made ESP8266WebServer::client() return a reference (fixes esp8266#7075)
bblanchon commentedon Feb 13, 2020
@earlephilhower , I opened #7080 .
I don't think it should break anything: since
WiFiClientis copy-constructible, a copy will be implicitly created if needed.devyte commentedon Feb 14, 2020
@earlephilhower @d-a-v I seem to remember this was already tried, and it did break something. Or maybe it was with WiFiServer::available()?
Made ESP8266WebServer::client() return a reference (fixes #7075) (#7080)