/** * 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()); }