amphp / amp

A non-blocking concurrency framework for PHP applications. 🐘

Home Page:https://amphp.org/amp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add Payload::readEntireBody?

withinboredom opened this issue · comments

Currently, to read an entire body you must write:

$body = '';
while($payload->isReadable()) {
  $body .= $payload->read();
}

A body larger than 8kb or so is truncated when simply doing a ->read()

Further, it would be nice to specify the number of bytes (in the case of Content-Length header being sent) when reading, and an exception should be thrown if the full size and exactly that size isn't met (so a 4xx response can be sent).

On another note, it would be nice if all these classes weren't final so modifications to behavior (like this) can be made through inheritance without having to open an issue.

What does this have to do with Amp? There is no Payload class here (if that is the class you're referring to; you didn't actually reference one.)

Payload only exists to make buffered consumption even easier, so there's of course already a method for that:

https://github.com/amphp/byte-stream/blob/daa00f2efdbd71565bf64ffefa89e37542addf93/src/Payload.php#L89

If you're referring to http-client: The content length is automatically enforced, so there's no need for changes. Generally, we prefer composition over inheritance, so all classes are final by default.