Skip to content

Commit

Permalink
Add case-insensitive header handling
Browse files Browse the repository at this point in the history
  • Loading branch information
cleptric committed Oct 11, 2023
1 parent 40be49e commit a4ab6e0
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/HttpClient/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ final class Response
*/
private $statusCode;

/**
* @var string[]
*/
private $headerNames = [];

/**
* @var string[][]
*/
Expand All @@ -32,6 +37,10 @@ public function __construct(int $statusCode, array $headers, string $error)
$this->statusCode = $statusCode;
$this->headers = $headers;
$this->error = $error;

foreach ($headers as $name => $value) {
$this->headerNames[strtolower($name)] = $name;
}
}

public function getStatusCode(): int
Expand All @@ -46,7 +55,7 @@ public function isSuccess(): bool

public function hasHeader(string $name): bool
{
return \array_key_exists($name, $this->headers);
return isset($this->headerNames[strtolower($name)]);
}

/**
Expand All @@ -58,6 +67,8 @@ public function getHeader(string $header): array
return [];

Check warning on line 67 in src/HttpClient/Response.php

View check run for this annotation

Codecov / codecov/patch

src/HttpClient/Response.php#L67

Added line #L67 was not covered by tests
}

$header = $this->headerNames[strtolower($header)];

return $this->headers[$header];
}

Expand Down

0 comments on commit a4ab6e0

Please sign in to comment.