@@ 13-41 (lines=29) @@ | ||
10 | * |
|
11 | * @author Soufiane Ghzal <[email protected]> |
|
12 | */ |
|
13 | class HeaderDefaultsPlugin implements Plugin |
|
14 | { |
|
15 | private $headers = []; |
|
16 | ||
17 | /** |
|
18 | * @param array $headers headers to set to the request |
|
19 | */ |
|
20 | public function __construct(array $headers) |
|
21 | { |
|
22 | $this->headers = $headers; |
|
23 | } |
|
24 | ||
25 | /** |
|
26 | * {@inheritdoc} |
|
27 | */ |
|
28 | public function handleRequest(RequestInterface $request, callable $next, callable $first) |
|
29 | { |
|
30 | foreach ($this->headers as $header => $headerValue) { |
|
31 | if (!$request->hasHeader($header)) { |
|
32 | $request = $request->withHeader($header, $headerValue); |
|
33 | } |
|
34 | } |
|
35 | ||
36 | return $next($request); |
|
37 | } |
|
38 | } |
|
39 |
@@ 12-38 (lines=27) @@ | ||
9 | * |
|
10 | * @author Soufiane Ghzal <[email protected]> |
|
11 | */ |
|
12 | class HeaderRemovePlugin implements Plugin |
|
13 | { |
|
14 | private $headers = []; |
|
15 | ||
16 | /** |
|
17 | * @param array $headers headers to remove from the request |
|
18 | */ |
|
19 | public function __construct(array $headers) |
|
20 | { |
|
21 | $this->headers = $headers; |
|
22 | } |
|
23 | ||
24 | /** |
|
25 | * {@inheritdoc} |
|
26 | */ |
|
27 | public function handleRequest(RequestInterface $request, callable $next, callable $first) |
|
28 | { |
|
29 | foreach ($this->headers as $header) { |
|
30 | if ($request->hasHeader($header)) { |
|
31 | $request = $request->withoutHeader($header); |
|
32 | } |
|
33 | } |
|
34 | ||
35 | return $next($request); |
|
36 | } |
|
37 | } |
|
38 |
@@ 13-39 (lines=27) @@ | ||
10 | * |
|
11 | * @author Soufiane Ghzal <[email protected]> |
|
12 | */ |
|
13 | class HeaderSetPlugin implements Plugin |
|
14 | { |
|
15 | private $headers = []; |
|
16 | ||
17 | /** |
|
18 | * @param array $headers headers to set to the request |
|
19 | */ |
|
20 | public function __construct(array $headers) |
|
21 | { |
|
22 | $this->headers = $headers; |
|
23 | } |
|
24 | ||
25 | /** |
|
26 | * {@inheritdoc} |
|
27 | */ |
|
28 | public function handleRequest(RequestInterface $request, callable $next, callable $first) |
|
29 | { |
|
30 | foreach ($this->headers as $header => $headerValue) { |
|
31 | $request = $request->withHeader($header, $headerValue); |
|
32 | } |
|
33 | ||
34 | return $next($request); |
|
35 | } |
|
36 | } |
|
37 |