Last active
January 12, 2018 03:36
-
-
Save never615/b018db2c693eaa5e644b8c30bb83de7b to your computer and use it in GitHub Desktop.
guzzle middleware tap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$middleware = Middleware::tap(function (RequestInterface $request, $options) use($log) { | |
$log->payload_format = isset($request->getHeader('Content-Type')[0]) ? $request->getHeader('Content-Type')[0] : null; | |
$log->payload = $request->getBody()->getContents(); | |
}, function ($request, $options, Promise $response) use($log) { | |
$response->then(function (ResponseInterface $response) use($log) { | |
$log->status = $response->getStatusCode(); | |
$log->response = $response->getBody()->getContents(); | |
$log->response_format = $log->payload_format = isset($response->getHeader('Content-Type')[0]) ? $response->getHeader('Content-Type')[0] : null; | |
$log->save(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment