Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Php 8 GuzzleHttp\Psr7\Stream::getContents stream is not getting the response content #1

Open
massimoconti opened this issue Jun 20, 2023 · 3 comments

Comments

@massimoconti
Copy link

As stated in the title running the library with php 8.1 trigger an unexpected behavior with \GuzzleHttp\Psr7\Stream::getContents.
For instance in ContactApi::requestContactExportWithHttpInfo this code:

if ($returnType === '\SplFileObject') {
    $content = $responseBody; //stream goes to serializer
} else {
    **$content = $responseBody->getContents();**
    if ($returnType !== 'string') {
        $content = json_decode($content);
    }
}

return a $content = "".

I didn't go into details, but I found that might be a stream issue.
If I cast $responseBody into a string it works as expected since $content turn to be something like {"processId":90} thank to magic method GuzzleHttp\Psr7\Stream::__toString.

$content = (string) $responseBody;

Maybe it's a guzzle http issue, not a brevo php sdk issue.

Thanks in advance

@massimoconti
Copy link
Author

Http api call works well, since logging it return me the expected response:

[2023-06-20T15:12:34.679754+02:00] brevo.INFO: POST /v3/contacts/export { "customContactFilter": { "actionForContacts": "unsubscribed", "listId": 2 } } - Response: 202 {"processId":90} [] []

@massimoconti
Copy link
Author

I found that the problem is connected with the logging operation. Since it consumes the stream messagge it is not available for reading it again, unless the client api force the rewind of the stream, which is accomplished for instance with the magic method __toString ($content = (string) $responseBody;) as stated above.

I guess it could be improved in swagger-codegen code generation.

@massimoconti
Copy link
Author

Look like someone else already got into the same problem:
swagger-api/swagger-codegen#11651

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant