| 1 | <?php |
||
| 10 | class HeaderPlugin implements Plugin |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var array headers that have fixed value |
||
| 14 | */ |
||
| 15 | private $headers = []; |
||
| 16 | private $removedHeader = []; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Sets a header with the given value to every requests. |
||
| 20 | * |
||
| 21 | * @param string $name name of the header |
||
| 22 | * @param string $value value of the header |
||
| 23 | * @param bool $override By default if the header is already set on the request the value wont be replaced |
||
| 24 | * pass $override to true to make the header value the same for every request |
||
| 25 | */ |
||
| 26 | 3 | public function withHeader($name, $value, $override = false) |
|
| 27 | { |
||
| 28 | 3 | $this->headers[$name] = ['value' => $value, 'override' => $override]; |
|
| 29 | 3 | } |
|
| 30 | |||
| 31 | /** |
||
| 32 | * Automatically removes the given header from the request. |
||
| 33 | * |
||
| 34 | * @param string $name name of the header to remove |
||
| 35 | */ |
||
| 36 | 2 | public function withoutHeader($name) |
|
| 40 | |||
| 41 | /** |
||
| 42 | * {@inheritdoc} |
||
| 43 | */ |
||
| 44 | 5 | public function handleRequest(RequestInterface $request, callable $next, callable $first) |
|
| 59 | } |
||
| 60 |