page->set_code() to set HTTP status

This commit is contained in:
Shish 2015-08-02 19:07:11 +01:00
parent 94244d762b
commit 90e86b99ae
5 changed files with 20 additions and 9 deletions

View File

@ -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;

View File

@ -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") {

View File

@ -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;
}

View File

@ -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());

View File

@ -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 {