namshi / cuzzle

This library let's you dump a Guzzle request to a cURL command for debug and log purpose.
https://github.com/namshi/cuzzle
330 stars 67 forks source link

fix reading request body after request has been sent #4

Closed vaidasm closed 9 years ago

vaidasm commented 9 years ago

This fixes the way stream contents is read. See: http://docs.guzzlephp.org/en/latest/streams.html#creating-streams

odino commented 9 years ago

hey @vaidasm thanks for the PR! Would you mind sharing a test case that was failing?

cheers!

vaidasm commented 9 years ago

Hi @odino, just added a simple testcase for this. $request->getBody()->getContents() is getting executed when request is being sent and when called the second time getContents returns empty string.

vaidasm commented 9 years ago

getContents is reads stream from current position until the end. If we call it before sending request, position is 0, so this method returns all the body string. After guzzle send the request, position is not zero (its at the end of stream) - and so, getContents returns empty string. The proper way of getting the entire body string is to cast body to string (or call __toString()).

You can test this behaviour: just run this test against current master.

odino commented 9 years ago

ah got it! then thanks man, we should merge it