/** * 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); } }
/** * Gets a HTTP header value * @param string $name Name of the header * @return string|array|null The value of the header, an array of values if * the header is set multiple times, null if not set * @see zibo\library\http\Header */ public function getHeader($name) { if (!$this->headers) { $this->headers = new HeaderContainer(); $this->headers->setHeadersFromServerRequest(); } if (!$this->headers->hasHeader($name)) { return null; } $header = $this->headers->getHeader($name); if (!is_array($header)) { return $header->getValue(); } $values = array(); foreach ($header as $h) { $values[] = $h->getValue(); } return $values; }
/** * Sets the response status code to not modified and removes illegal headers * for such a response code * @return null */ public function setNotModified() { $this->setStatusCode(self::STATUS_CODE_NOT_MODIFIED); $this->setView(null); $removeHeaders = array(Header::HEADER_ALLOW, Header::HEADER_CONTENT_ENCODING, Header::HEADER_CONTENT_LANGUAGE, Header::HEADER_CONTENT_LENGTH, Header::HEADER_CONTENT_MD5, Header::HEADER_CONTENT_TYPE, Header::HEADER_LAST_MODIFIED); $this->headers->removeHeader($removeHeaders); }