-
Notifications
You must be signed in to change notification settings - Fork 153
Description
When attempting to download a DriveItem by utilizing a Stream object as the Return Type, the resultant Stream contents is empty.
This is due to the fact that the GraphRequest execute method first wraps the response into a new GraphResponse. The constructor for GraphResponse attempts to decode the contents of the response into a json object by using a json_decode function call. This function call takes the Stream as the first parameter, thus calling the Stream's __toString method which will read the entire contents of the stream and return as a string, therefore consuming the entire string.
After the constructor for the GraphResponse is called, then GraphRequest checks to see if $this->returnType is set, if so, then calls the GraphResponse's getResponseAsObject which indeed returns the Stream object, but at this point the Stream object is exhausted.
Proposed solution:
Modify the execute (and executeAsync) method to check if $this->returnType is "GuzzleHttp\Psr7\Stream". If so, do not wrap the response into a GraphResponse but instead immediately return the Stream object from thje Guzzle result. This can be similarly done in the async version.
This also will allow removing the code from GetResponse inside getResponseAsObject to check for returnType being a Stream and then returning $this->_body, since it's already exhausted and who cares.
Pull request to come.