/** * Send a HTTP response. * * @param int $code * @param string $mimetype * @param string $body * @param array $headers * @return void */ private function returnResponse($code, $body = '', $mimetype = 'text/plain', array $headers = array()) { $msg = new HttpMessage(); $msg->setType(HttpMessage::TYPE_RESPONSE); $msg->setResponseCode($code); $msg->setResponseStatus(self::$statuses[$code]); $headers['Content-Type'] = (string) $mimetype; $headers['Content-Length'] = (string) strlen($body); $msg->setHeaders($headers); $msg->setBody($body); fwrite($this->conn, $msg->toString()); }
/** * Set all of the headers. This will overwrite any existing headers. * * @param array|string $headers An array or string of headers to set. * * The array of headers can be in the following form: * * - ["Header-Name" => "value", ...] * - ["Header-Name" => ["lines, ...], ...] * - ["Header-Name: value", ...] * - Any combination of the above formats. * * A header string is the the form of the HTTP standard where each Key: Value pair is separated by `\r\n`. * * @return HttpResponse Returns `$this` for fluent calls. */ public function setHeaders($headers) { parent::setHeaders($headers); if ($statusLine = $this->parseStatusLine($headers)) { $this->setStatus($statusLine); } return $this; }