|
5 | 5 | use Lkrms\Concern\Immutable; |
6 | 6 | use Lkrms\Concern\ImmutableArrayAccess; |
7 | 7 | use Lkrms\Concern\TReadableCollection; |
8 | | -use Lkrms\Contract\Arrayable; |
9 | 8 | use Lkrms\Contract\ICollection; |
10 | 9 | use Lkrms\Exception\InvalidArgumentException; |
| 10 | +use Lkrms\Http\Catalog\HttpHeader; |
| 11 | +use Lkrms\Http\Contract\IAccessToken; |
11 | 12 | use Lkrms\Http\Contract\IHttpHeaders; |
12 | 13 | use Lkrms\Support\Catalog\RegularExpression as Regex; |
13 | 14 | use Lkrms\Utility\Arr; |
@@ -69,7 +70,7 @@ public function addLine(string $line, bool $strict = false) |
69 | 70 |
|
70 | 71 | if ($line === "\r\n" || (!$strict && trim($line) === '')) { |
71 | 72 | if ($strict && $this->Closed) { |
72 | | - throw new InvalidArgumentException('HTTP message cannot have empty line after body'); |
| 73 | + throw new InvalidArgumentException('HTTP message cannot have empty header after body'); |
73 | 74 | } |
74 | 75 | return $this->with('Closed', true)->with('Carry', null); |
75 | 76 | } |
@@ -250,6 +251,19 @@ public function merge($items, bool $preserveExisting = false) |
250 | 251 | return $this->replaceHeaders($headers, $index); |
251 | 252 | } |
252 | 253 |
|
| 254 | + /** |
| 255 | + * @inheritDoc |
| 256 | + */ |
| 257 | + public function authorize( |
| 258 | + IAccessToken $token, |
| 259 | + string $headerName = HttpHeader::AUTHORIZATION |
| 260 | + ) { |
| 261 | + return $this->set( |
| 262 | + $headerName, |
| 263 | + sprintf('%s %s', $token->getType(), $token->getToken()) |
| 264 | + ); |
| 265 | + } |
| 266 | + |
253 | 267 | /** |
254 | 268 | * @inheritDoc |
255 | 269 | */ |
@@ -285,21 +299,19 @@ public function filter(callable $callback, int $mode = ICollection::CALLBACK_USE |
285 | 299 | $changed = false; |
286 | 300 |
|
287 | 301 | foreach ($index as $nextLower => $headerIndex) { |
288 | | - $nextKey = null; |
289 | 302 | $nextValue = null; |
290 | 303 | foreach ($headerIndex as $i) { |
291 | 304 | $header = $this->Headers[$i]; |
292 | 305 | $value = reset($header); |
293 | | - $nextKey ??= key($header); |
294 | 306 | if ($mode === ICollection::CALLBACK_USE_KEY) { |
295 | 307 | break; |
296 | 308 | } |
297 | 309 | $nextValue[] = $value; |
298 | 310 | } |
299 | 311 | $next = $mode === ICollection::CALLBACK_USE_KEY |
300 | | - ? $nextKey |
| 312 | + ? $nextLower |
301 | 313 | : ($mode === ICollection::CALLBACK_USE_BOTH |
302 | | - ? [$nextKey => $nextValue] |
| 314 | + ? [$nextLower => $nextValue] |
303 | 315 | : $nextValue); |
304 | 316 | if ($count++) { |
305 | 317 | if (!$callback($item, $next, $prev)) { |
|
0 commit comments