Skip to content

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

Closed

Description

@bblanchon

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

Activity

  1. earlephilhower commented on Feb 12, 2020

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

  2. added a commit that references this issue on Feb 13, 2020
    044279e
  3. bblanchon commented on Feb 13, 2020

    @bblanchon
    ContributorAuthor

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

  4. devyte commented on Feb 14, 2020

    @devyte
    Collaborator

    @earlephilhower @d-a-v I seem to remember this was already tried, and it did break something. Or maybe it was with WiFiServer::available()?

  5. added a commit that references this issue on Jul 17, 2020
    c18f7cb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions