public function DebugMessageFormatterPluginBase::formatResponse in Apigee Edge 8
Formats a response.
Parameters
\Psr\Http\Message\ResponseInterface $response: Response object.
\Psr\Http\Message\RequestInterface $request: Request object that triggered the response.
Return value
string Formatted response.
Overrides DebugMessageFormatterPluginInterface::formatResponse
1 call to DebugMessageFormatterPluginBase::formatResponse()
- FullHttpMessageFormatter::formatResponse in modules/
apigee_edge_debug/ src/ Plugin/ DebugMessageFormatter/ FullHttpMessageFormatter.php - Formats a response.
1 method overrides DebugMessageFormatterPluginBase::formatResponse()
- FullHttpMessageFormatter::formatResponse in modules/
apigee_edge_debug/ src/ Plugin/ DebugMessageFormatter/ FullHttpMessageFormatter.php - Formats a response.
File
- modules/
apigee_edge_debug/ src/ Plugin/ DebugMessageFormatter/ DebugMessageFormatterPluginBase.php, line 128
Class
- DebugMessageFormatterPluginBase
- Defines a base class for debug message formatter plugins.
Namespace
Drupal\apigee_edge_debug\Plugin\DebugMessageFormatterCode
public function formatResponse(ResponseInterface $response, RequestInterface $request) : string {
if ($this->removeCredentials) {
$request = $request
->withoutHeader('Authorization');
$masks = [
'consumerKey' => '***consumer-key***',
'consumerSecret' => '***consumer-secret***',
];
$json = json_decode((string) $response
->getBody(), TRUE);
if (json_last_error() === JSON_ERROR_NONE) {
array_walk_recursive($json, function (&$value, $key) use ($masks) {
if (isset($masks[$key])) {
$value = $masks[$key];
}
});
$response = $response
->withBody(Psr7\stream_for(json_encode((object) $json, JSON_PRETTY_PRINT)));
}
if ($request
->getMethod() === 'POST' && $request
->getUri()
->getPath() === '/oauth/token') {
$json = json_decode((string) $response
->getBody(), TRUE);
if (json_last_error() === JSON_ERROR_NONE) {
if (isset($json['access_token'])) {
$json['access_token'] = '***access-token***';
}
if (isset($json['refresh_token'])) {
$json['refresh_token'] = '***refresh-token***';
}
$response = $response
->withBody(Psr7\stream_for(json_encode((object) $json)));
}
}
}
return $this
->getFormatter()
->formatResponse($response);
}