From 90e86b99aecacf970262dfe1d7910b9b7080a95e Mon Sep 17 00:00:00 2001 From: Shish Date: Sun, 2 Aug 2015 19:07:11 +0100 Subject: [PATCH] page->set_code() to set HTTP status --- core/basethemelet.class.php | 2 +- core/page.class.php | 11 +++++++++++ ext/danbooru_api/main.php | 12 ++++++------ ext/handle_404/main.php | 2 +- ext/image/main.php | 2 +- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/core/basethemelet.class.php b/core/basethemelet.class.php index acae9a52..2996200c 100644 --- a/core/basethemelet.class.php +++ b/core/basethemelet.class.php @@ -16,7 +16,7 @@ class BaseThemelet { */ public function display_error(/*int*/ $code, /*string*/ $title, /*string*/ $message) { global $page; - $page->add_http_header("HTTP/1.0 $code $title"); + $page->set_code($code); $page->set_title($title); $page->set_heading($title); $has_nav = false; diff --git a/core/page.class.php b/core/page.class.php index 4aeb5ad0..7f90a982 100644 --- a/core/page.class.php +++ b/core/page.class.php @@ -111,6 +111,9 @@ class Page { /** @name "page" mode */ //@{ + /** @var int */ + public $code = 200; + /** @var string */ public $title = ""; @@ -132,6 +135,13 @@ class Page { /** @var Block[] */ public $blocks = array(); + /** + * Set the HTTP status code + * @param int $code + */ + public function set_code($code) { + $this->code = $code; + } /** * Set the window title. @@ -225,6 +235,7 @@ class Page { switch($this->mode) { case "page": + header("HTTP/1.0 {$this->code} Shimmie"); if(CACHE_HTTP) { header("Vary: Cookie, Accept-Encoding"); if($user->is_anonymous() && $_SERVER["REQUEST_METHOD"] == "GET") { diff --git a/ext/danbooru_api/main.php b/ext/danbooru_api/main.php index d1710660..557dda2e 100644 --- a/ext/danbooru_api/main.php +++ b/ext/danbooru_api/main.php @@ -140,7 +140,7 @@ class DanbooruApi extends Extension { { $fp = fopen($url, "r"); if(!$fp) { - $page->add_http_header("HTTP/1.0 409 Conflict"); + $page->set_code(409); $page->add_http_header("X-Danbooru-Errors: fopen read error"); } @@ -174,7 +174,7 @@ class DanbooruApi extends Extension { $filename = basename($url); } else { // Nothing was specified at all - $page->add_http_header("HTTP/1.0 409 Conflict"); + $page->set_code(409); $page->add_http_header("X-Danbooru-Errors: no input files"); return; } @@ -187,7 +187,7 @@ class DanbooruApi extends Extension { { if(strtolower($_REQUEST['md5']) != $hash) { - $page->add_http_header("HTTP/1.0 409 Conflict"); + $page->set_code(409); $page->add_http_header("X-Danbooru-Errors: md5 mismatch"); return; } @@ -198,7 +198,7 @@ class DanbooruApi extends Extension { // Does it exist already? $existing = Image::by_hash($hash); if(!is_null($existing)) { - $page->add_http_header("HTTP/1.0 409 Conflict"); + $page->set_code(409); $page->add_http_header("X-Danbooru-Errors: duplicate"); $existinglink = make_link("post/view/" . $existing->id); if($danboorup_kludge) $existinglink=make_http($existinglink); @@ -235,13 +235,13 @@ class DanbooruApi extends Extension { } catch(UploadException $ex) { // Did something screw up? - $page->add_http_header("HTTP/1.0 409 Conflict"); + $page->set_code(409); $page->add_http_header("X-Danbooru-Errors: exception - " . $ex->getMessage()); return; } } else { - $page->add_http_header("HTTP/1.0 409 Conflict"); + $page->set_code(409); $page->add_http_header("X-Danbooru-Errors: authentication error"); return; } diff --git a/ext/handle_404/main.php b/ext/handle_404/main.php index 00a850e8..241b8fda 100644 --- a/ext/handle_404/main.php +++ b/ext/handle_404/main.php @@ -31,7 +31,7 @@ class Handle404 extends Extension { } else { log_debug("handle_404", "Hit 404: $h_pagename"); - $page->add_http_header("HTTP/1.0 404 Page Not Found",5); + $page->set_code(404); $page->set_title("404"); $page->set_heading("404 - No Handler Found"); $page->add_block(new NavBlock()); diff --git a/ext/image/main.php b/ext/image/main.php index 98ef2fb7..bdd1978c 100644 --- a/ext/image/main.php +++ b/ext/image/main.php @@ -407,7 +407,7 @@ class ImageIO extends Extension { $gmdate_mod = gmdate('D, d M Y H:i:s', filemtime($file)) . ' GMT'; if($if_modified_since == $gmdate_mod) { - $page->add_http_header("HTTP/1.0 304 Not Modified",3); + $page->set_code(304); $page->set_data(""); } else {