@@ -72,8 +72,12 @@ class Csp extends \Laminas\View\Helper\AbstractHelper
             as $field
         ) {
             if ($cspHeaders = $headers->get($field)) {
-                foreach ((array)$cspHeaders as $header) {
-                    $headers->removeHeader($header);
+                if ($cspHeaders instanceof \ArrayIterator) {
+                    foreach ($cspHeaders as $header) {
+                        $headers->removeHeader($header);
+                    }
+                } else {
+                    $headers->removeHeader($cspHeaders);
                 }
             }
         }
<?php
/**
 * Content Security Policy view helper
 *
 * PHP version 7
 *
 * Copyright (C) The National Library of Finland 2021.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category VuFind
 * @package  View_Helpers
 * @author   Ere Maijala <ere.maijala@helsinki.fi>
 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
 * @link     http://vufind.org/wiki/vufind2:developer_manual Wiki
 */
namespace VuFind\View\Helper\Root;

use Laminas\Http\Response;

/**
 * Content Security Policy view helper
 *
 * @category VuFind
 * @package  View_Helpers
 * @author   Ere Maijala <ere.maijala@helsinki.fi>
 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
 * @link     http://vufind.org/wiki/vufind2:developer_manual Wiki
 */
class Csp extends \Laminas\View\Helper\AbstractHelper
{
    /**
     * Response object
     *
     * @var Response
     */
    protected $response;

    /**
     * Constructor
     *
     * @param Response $response HTTP Response, if any
     */
    public function __construct(?Response $response)
    {
        $this->response = $response;
    }

    /**
     * Disable Content Security Policy by removing the headers
     *
     * @return void
     */
    public function disablePolicy()
    {
        if (null === $this->response) {
            return;
        }
        $headers = $this->response->getHeaders();
        foreach (['Content-Security-Policy', 'Content-Security-Policy-Report-Only']
            as $field
        ) {
            if ($cspHeaders = $headers->get($field)) {
                foreach ((array)$cspHeaders as $header) {
                    $headers->removeHeader($header);
                }
            }
        }
    }
}

Would `is_iterable()` be a more generic way of doing this?