From 85a59e08f579973bb7b2af26f676b615c79d26eb Mon Sep 17 00:00:00 2001 From: Brandon Fowler Date: Tue, 19 Sep 2023 20:37:51 -0400 Subject: [PATCH] Move headers out of getJson functions --- api/index.php | 3 +++ includes/LinkCount.php | 5 ----- includes/ProjectPrefixSearch.php | 4 ---- projects/index.php | 1 + 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/api/index.php b/api/index.php index 8e0abf9..1d8ec9f 100644 --- a/api/index.php +++ b/api/index.php @@ -3,7 +3,10 @@ require '../vendor/autoload.php'; if ($_SERVER['QUERY_STRING']) { + header('Content-Type: application/json'); + header('Access-Control-Allow-Origin: *'); echo (new LinkCount(get('page'), get('project'), get('namespaces')))->getJson(); + exit; } diff --git a/includes/LinkCount.php b/includes/LinkCount.php index a0336df..a7fcf7b 100644 --- a/includes/LinkCount.php +++ b/includes/LinkCount.php @@ -233,11 +233,6 @@ public function getHtml() { } public function getJson() { - if (!headers_sent()) { - header('Content-Type: application/json'); - header('Access-Control-Allow-Origin: *'); - } - if (isset($this->error)) { return json_encode(['error' => $this->error]); } diff --git a/includes/ProjectPrefixSearch.php b/includes/ProjectPrefixSearch.php index 5b220c5..1a6811b 100644 --- a/includes/ProjectPrefixSearch.php +++ b/includes/ProjectPrefixSearch.php @@ -28,10 +28,6 @@ public function __construct($prefix) { } public function getJson() { - if (!headers_sent()) { - header('Content-Type: application/json'); - } - return json_encode([ 'projects' => $this->projects, 'exact' => $this->exact diff --git a/projects/index.php b/projects/index.php index 4bb641a..53dd90f 100644 --- a/projects/index.php +++ b/projects/index.php @@ -2,4 +2,5 @@ require '../vendor/autoload.php'; +header('Content-Type: application/json'); echo (new ProjectPrefixSearch(get('prefix')))->getJson();