-
Notifications
You must be signed in to change notification settings - Fork 76
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
Not compatible with gmponos/guzzle_logger #166
Comments
Workaround: use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Utils;
use Psr\Http\Message\ResponseInterface;
// Without this, we get the following error from the logger middleware:
//
// "StringHandler can not log request/response because the body is not seekable/readable"
//
// It happens because the cache handler returns the body in the form of PumpStream which
// is not rewindable. To fix, we simply read and copy the stream to a rewindable stream.
//
$handler->push(Middleware::mapResponse(
fn (ResponseInterface $response) => $response->withBody(
Psr7Utils::streamFor((string) $response->getBody())
)
));
// Add the cache middleware
$handler->push($cacheMiddleware, 'cache'); |
I'm using the cache middleware w/ gmponos without error. I'm using Monolog rather than StringHandler, so perhaps it's StringHandler specifically that isn't compatible. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Since CacheEntry uses PumpStream for the response, attempting to use this middleware with gmponos/guzzle-log-middleware results in the following error:
The text was updated successfully, but these errors were encountered: