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 #95

Closed
vanoostrum opened this issue Feb 6, 2023 · 2 comments
Closed

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

@vanoostrum
Copy link
Author

My apologies. This issue belongs in the repo https://github.com/kelunik/acme. I will move it to there

@vanoostrum
Copy link
Author

I created the issue here: kelunik/acme#39. Closing this issue now.

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