Remove the X-generator header from the response I want to remove the CMS type and version disclosure , which Drupal is returning in the X-Generator:Drupal 8 (https://www.drupal.org) header.

I am using the following code, but it removes the x-generator header, but I can still see X-Generator:Drupal 8 (https://www.drupal.org) in the browser header response.

function xxx_page_attachments_alter(&amp;$data, &amp;$context1 = NULL, &amp;$context2 = NULL) {
    foreach ($data['#attached']['html_head'] as $key =&gt; $attachment) {
        if ($attachment[1] == 'system_meta_generator') {
          unset($data['#attached']['html_head'][$key]);
        }
    }
}


How can I fix my code?
The simplest method is to remove the header in a custom EventSubscriber:

$response-&gt;headers-&gt;remove('X-Generator');


See https://drupal.stackexchange.com/a/201297/47547 for an example.