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

AcmeService Exception handling: Can't buffer() a payload more than once #39

Open
vanoostrum opened this issue Feb 6, 2023 · 1 comment
Labels

Comments

@vanoostrum
Copy link

In the class Kelunik/Acme/AcmeService the following piece of code occurs on multiple occasions in slightly different forms:

try {
    return Authorization::fromResponse($url, $response->getBody()->buffer());
} catch (\Throwable $_) {
    throw $this->generateException($response, $response->getBody()->buffer());
}

This can lead to the following Exception: "Can't buffer() a payload more than once" in /vendor/amphp/byte-stream/src/Payload.php(96)

This happens when there is a response which cannot be parsed successfully. The method $response->getBody()->buffer() is called twice in this situation, resulting in the error above.

A solution for this issue could be to first store the responseBuffer in a local variable, to avoid reading it twice:

$responseBuffer = $response->getBody()->buffer()
try {
    return Authorization::fromResponse($url, responseBuffer);
} catch (\Throwable $_) {
    throw $this->generateException($response, responseBuffer);
}

If you prefer I could make a pull request for this

@kelunik
Copy link
Owner

kelunik commented Feb 6, 2023

Thanks for reporting! I guess this is new in the new major version of the http-client, as previously multiple buffer calls have been allowed.

@kelunik kelunik added the bug label Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants