/**
  * Scans the body of the request message and replaces any nonce
  * placeholders with actual nonces, that we'll then add to our
  * headers.
  *
  * @param ResponseInterface $response
  */
 protected function generateNonces(ResponseInterface &$response)
 {
     $body = $response->getBody();
     if (empty($body)) {
         return;
     }
     if (!is_array($this->styleSrc)) {
         $this->styleSrc = [$this->styleSrc];
     }
     if (!is_array($this->scriptSrc)) {
         $this->scriptSrc = [$this->scriptSrc];
     }
     // Replace style placeholders with nonces
     $body = preg_replace_callback('/{csp-style-nonce}/', function ($matches) {
         $nonce = bin2hex(random_bytes(12));
         $this->styleSrc[] = 'nonce-' . $nonce;
         return 'nonce=' . $nonce;
     }, $body);
     // Replace script placeholders with nonces
     $body = preg_replace_callback('/{csp-script-nonce}/', function ($matches) {
         $nonce = bin2hex(random_bytes(12));
         $this->scriptSrc[] = 'nonce-' . $nonce;
         return 'nonce=' . $nonce;
     }, $body);
     $response->setBody($body);
 }