laminas / laminas-diactoros

PSR HTTP Message implementations
https://docs.laminas.dev/laminas-diactoros/
BSD 3-Clause "New" or "Revised" License
470 stars 62 forks source link

V3 getBody()->getContents() no longer returns full stream on second call #160

Open BackEndTea opened 1 year ago

BackEndTea commented 1 year ago

BC Break Report

Q A
Version 3.0.0

Summary

In v2, the default the default behaviour of the ServerRequestyFActory was to return a request object, where you could get the contents of the body multiple times. in v3, every new read of getContents() will result in an empty string. (Casting the body to a string still works as before).

Since the way it currently works is correct according to PSR implementation, it should probably be updated in the migration guide. And it should not be changed back to the v2 implementation

Previous behavior

getBody->getContents would return the full stream every time

Current behavior

getBody->getContents will return the full stream the first time, and then an empty string on consecutive calls.

How to reproduce

Send a post request and call request->getBody()->getContents() multiple times.

Xerkus commented 1 year ago

This is expected behavior as per PSR interface getContents() is stream pointer aware:

Returns the remaining contents in a string

For multiple invocations of getContents() stream must be rewound. It can not be rewound if it is not seekable.

Previous implementation was bugged. See #150

Xerkus commented 1 year ago

Reopening as documentation issue. Mention of behavior fix can be added to migration guide.

BackEndTea commented 1 year ago

Thanks, ill try snd update the docs tomorrow