From 64764fb9fac0227f8e0443e7c7519d73aec275b9 Mon Sep 17 00:00:00 2001 From: Murilo Ijanc Date: Sun, 26 Jul 2026 14:58:55 -0300 Subject: Initial import --- src/Response.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/Response.php (limited to 'src/Response.php') diff --git a/src/Response.php b/src/Response.php new file mode 100644 index 0000000..f0ecb8d --- /dev/null +++ b/src/Response.php @@ -0,0 +1,50 @@ +> $headers Response headers. + * Keys may be in any case and values may be a single string or a list + * of them; {@see Response::header()} handles both, so an implementer + * can pass through whatever their HTTP layer produced. + */ + public function __construct( + public readonly int $status, + public readonly array $headers = [], + public readonly string $body = '', + ) { + } + + /** + * Look a header up case-insensitively, returning the first value or `null` + * when it is absent. + */ + public function header(string $name): ?string + { + foreach ($this->headers as $key => $value) { + if (strcasecmp((string) $key, $name) !== 0) { + continue; + } + if (is_array($value)) { + $value = $value[array_key_first($value)] ?? null; + } + + return is_scalar($value) ? (string) $value : null; + } + + return null; + } +} -- cgit v1.3