. */ namespace Volkszaehler\View\HTTP; /** * HTTP request * * simple class to control the output buffering * * @author Steffen Vogel * @package http */ class Response { protected $headers = array(); protected $code = 200; // default code (OK) protected static $codes = array( 100 => 'Continue', 101 => 'Switching Protocols', 200 => 'OK', // success 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 300 => 'Multiple Choicesv', 301 => 'Moved Permanently', // redirection 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect', 400 => 'Bad Request', // client error 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Timeout', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Long', 415 => 'Unsupported Media Type', 416 => 'Requested Range Not Satisfiable', 417 => 'Expectation Failed', 500 => 'Internal Server Error', // server error 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported' ); /** * constructor */ public function __construct() { $this->headers = self::getHeaders(); ob_start(array($this, 'obCallback')); } protected static function getHeaders() { if (function_exists('apache_response_headers')) { return apache_response_headers(); } else { $headers = array(); foreach (headers_list() as $header) { $sp = strpos($header, ':'); $headers[substr($header, 0, $sp)] = substr($header, $sp); } return $headers; } } public function obCallback($output) { return $output; // simple passthrough } public function send() { // change returncode header('HTTP/1.1 ' . $this->code . ' ' . self::getCodeDescription($this->code)); // send headers foreach ($this->headers as $name => $value) { header($name . ': ' . $value); } ob_end_flush(); } /** * setter & getter */ public function setHeader($header, $value) { $this->headers[$header] = $value; } public function getHeader($header) { return $this->headers[$header]; } public function getCode() { return $this->code; } public function setCode($code) { $this->code = $code; } static public function getCodeDescription($code) { return (isset(self::$codes[$code])) ? self::$codes[$code] : FALSE; } } ?>