public function DebugMessageFormatterPluginBase::formatRequest in Apigee Edge 8
Formats a request.
Parameters
\Psr\Http\Message\RequestInterface $request: Request object.
Return value
string Formatted request.
Overrides DebugMessageFormatterPluginInterface::formatRequest
File
- modules/
apigee_edge_debug/ src/ Plugin/ DebugMessageFormatter/ DebugMessageFormatterPluginBase.php, line 94
Class
- DebugMessageFormatterPluginBase
- Defines a base class for debug message formatter plugins.
Namespace
Drupal\apigee_edge_debug\Plugin\DebugMessageFormatterCode
public function formatRequest(RequestInterface $request) : string {
// Do not modify the original request object.
if ($this->removeCredentials) {
$request = $request
->withoutHeader('Authorization');
if ($request
->getMethod() === 'POST' && $request
->getUri()
->getPath() === '/oauth/token') {
$body = (string) $request
->getBody();
$body = preg_replace('/(.*refresh_token=)([^\\&]+)(.*)/', '$1***refresh-token***$3', $body);
$body = preg_replace('/(.*mfa_token=)([^\\&]+)(.*)/', '$1***mfa-token***$3', $body);
$body = preg_replace('/(.*username=)([^\\&]+)(.*)/', '$1***username***$3', $body);
$body = preg_replace('/(.*password=)([^\\&]+)(.*)/', '$1***password***$3', $body);
$request = $request
->withBody(Psr7\stream_for($body));
}
}
if ($this->maskOrganization) {
$pattern = '/(\\/v\\d+\\/(?:mint\\/)?(?:o|organizations))(?:\\/)([^\\/]+)(?:\\/?)(.*)/';
$path = rtrim(preg_replace($pattern, '$1/***organization***/$3', $request
->getUri()
->getPath()), '/');
$request = $request
->withUri($request
->getUri()
->withPath($path));
}
return $this
->getFormatter()
->formatRequest($request);
}