Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP8266WebServer::client() should return a reference #7075

Closed
bblanchon opened this issue Feb 11, 2020 · 3 comments · Fixed by #7080
Closed

ESP8266WebServer::client() should return a reference #7075

bblanchon opened this issue Feb 11, 2020 · 3 comments · Fixed by #7080

Comments

@bblanchon
Copy link
Contributor

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

@earlephilhower
Copy link
Collaborator

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...

bblanchon added a commit to bblanchon/esp8266-Arduino that referenced this issue Feb 13, 2020
@bblanchon
Copy link
Contributor Author

bblanchon commented Feb 13, 2020

@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.

@devyte
Copy link
Collaborator

devyte commented 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()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants