Beispiel #1
0
 /**
  * Sets the status code and sends the headers to the client
  * @param int $statusCode HTTP response status code
  * @param zibo\library\http\HeaderContainer $headers Container of the headers
  * @return null
  * @throws zibo\ZiboException when the output already started
  * @see zibo\library\http\Header
  */
 protected function sendHeaders($statusCode, HeaderContainer $headers)
 {
     if (!$headers->hasHeaders() && $statusCode === Response::STATUS_CODE_OK) {
         return;
     }
     if (headers_sent($file, $line)) {
         throw new ZiboException('Cannot send headers, output already started in ' . $file . ' on line ' . $line);
     }
     // set the status code
     $protocol = 'HTTP/1.0';
     if (isset($_SERVER['SERVER_PROTOCOL'])) {
         $protocol = $_SERVER['SERVER_PROTOCOL'];
     }
     header($protocol . ' ' . $statusCode);
     // set the headers
     foreach ($headers as $header) {
         header((string) $header, false);
     }
 }