diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2026-05-28 06:59:47 +0300 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2026-05-28 06:59:47 +0300 |
| commit | 78bfc53e084afddcff6450173ae594ee8df279ac (patch) | |
| tree | ab29a1be6b046e61306393112fb65cc2c9e9d12d /classes | |
| parent | 69b46e2fd39294d347206edd8b4ea01b749bdb51 (diff) | |
| download | the-epube-78bfc53e084afddcff6450173ae594ee8df279ac.tar.gz the-epube-78bfc53e084afddcff6450173ae594ee8df279ac.tar.xz | |
try setting content-type conditionally, remove duplicate testcase code
Diffstat (limited to 'classes')
| -rw-r--r-- | classes/Response.php | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/classes/Response.php b/classes/Response.php index a0620ae..8d32496 100644 --- a/classes/Response.php +++ b/classes/Response.php @@ -6,6 +6,7 @@ class Response /** @var array<string, string> */ private array $headers = []; private string $body = ''; + private string $contentType = "text/json"; public function withStatus(int $code, string $reasonPhrase = ''): self { @@ -35,11 +36,20 @@ class Response public function send(): void { + $contentTypeFound = false; + if ($this->headers) { foreach ($this->headers as $name => $value) { header("$name: $value"); + + if (strtolower($name) === "content-type") + $contentTypeFound = true; } } + + if (!$contentTypeFound) + header("Content-type: {$this->contentType}"); + http_response_code($this->status); echo $this->body; } |
