commit 93372545b51451362da9cbbca79cf2b36277209b
parent 0c16ee3b1389419e3a1c17be51251598b4ae8d49
Author: dankert <devnull@localhost>
Date: Sat, 8 Dec 2007 02:05:41 +0100
Bei HTTP-ServerErrorn JSON- und XML-Clients entsprechend bedienen.
Diffstat:
1 file changed, 37 insertions(+), 3 deletions(-)
diff --git a/serviceClasses/Http.class.php b/serviceClasses/Http.class.php
@@ -419,10 +419,32 @@ class Http
echo "$status $text\n$message";
exit;
}
+
header('HTTP/1.0 '.intval($status).' '.$text);
- header('Content-Type: text/html');
- $signature = OR_TITLE.' '.OR_VERSION.' '.getenv('SERVER_SOFTWARE');
- echo <<<HTML
+
+
+ $types = Http::getAccept();
+
+ if ( sizeof($types)==1 && in_array('application/json',$types) )
+ {
+ header('Content-Type: application/json');
+ require_once( OR_SERVICECLASSES_DIR."JSON.class.".PHP_EXT );
+ $json = new JSON();
+ echo $json->encode( array('status'=>$status,'error'=>$text,'description'=>$message) );
+ }
+ elseif ( sizeof($types)==1 && in_array('application/xml',$types) )
+ {
+ header('Content-Type: application/xml');
+ require_once( OR_SERVICECLASSES_DIR."XML.class.".PHP_EXT );
+ $xml = new XML();
+ $xml->root='error';
+ echo $xml->encode( array('status'=>$status,'error'=>$text,'description'=>$message) );
+ }
+ else
+ {
+ header('Content-Type: text/html');
+ $signature = OR_TITLE.' '.OR_VERSION.' '.getenv('SERVER_SOFTWARE');
+ echo <<<HTML
<html>
<head><title>$status $text - OpenRat</title></head>
<body>
@@ -433,8 +455,20 @@ class Http
</body>
</html>
HTML;
+ }
exit;
}
+
+
+ /**
+ *
+ * @return Array Mime-Typen, welche vom User-Agent akzeptiert werden.
+ */
+ function getAccept()
+ {
+ $httpAccept = getenv('HTTP_ACCEPT');
+ return $types = explode(',',$httpAccept);
+ }
}
?>
\ No newline at end of file