The function does not work in ESP8266

Agreed
Instead of

it would be better something like it:

 if (client  && client.available()) {
   String request = client.readStringUntil('\r');
   client.flush();
  ...  // work with request