# decalog/4.4.0/includes/libraries/http/client-common/Plugin/HeaderRemovePlugin.php

DecaLog, version 4.4.0. 45 lines.

- Page: https://pluginprobe.com/plugins/decalog/4.4.0/code/includes/libraries/http/client-common/Plugin/HeaderRemovePlugin.php
- Raw: https://pluginprobe.com/plugins/decalog/4.4.0/raw/includes/libraries/http/client-common/Plugin/HeaderRemovePlugin.php
- Modified: 2024-05-13T07:42:54+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/decalog/4.4.0/code/includes/libraries/http/client-common/Plugin/HeaderRemovePlugin.php#L10-L20`.

```php
<?php

declare(strict_types=1);

namespace Http\Client\Common\Plugin;

use Http\Client\Common\Plugin;
use Http\Promise\Promise;
use Psr\Http\Message\RequestInterface;

/**
 * Removes headers from the request.
 *
 * @author Soufiane Ghzal <sghzal@gmail.com>
 */
final class HeaderRemovePlugin implements Plugin
{
    /**
     * @var array
     */
    private $headers = [];

    /**
     * @param array $headers List of header names to remove from the request
     */
    public function __construct(array $headers)
    {
        $this->headers = $headers;
    }

    /**
     * {@inheritdoc}
     */
    public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
    {
        foreach ($this->headers as $header) {
            if ($request->hasHeader($header)) {
                $request = $request->withoutHeader($header);
            }
        }

        return $next($request);
    }
}

```
