/**
  * @param array $record
  * @return bool
  */
 protected function write(array $record)
 {
     ini_set('display_errors', 0);
     // TODO: This coupling isn't ideal
     // See https://github.com/silverstripe/silverstripe-framework/issues/4484
     if (Controller::has_curr()) {
         $response = Controller::curr()->getResponse();
     } else {
         $response = new HTTPResponse();
     }
     // If headers have been sent then these won't be used, and may throw errors that we wont' want to see.
     if (!headers_sent()) {
         $response->setStatusCode($this->statusCode);
         $response->addHeader("Content-Type", $this->contentType);
     } else {
         // To supress errors aboot errors
         $response->setStatusCode(200);
     }
     $response->setBody($record['formatted']);
     $response->output();
     return false === $this->bubble;
 }
 /**
  * @param HTTPResponse|string $body Either the plaintext content of the error
  * message, or an HTTPResponse object representing it. In either case, the
  * $statusCode and $statusDescription will be the HTTP status of the resulting
  * response.
  * @param int $statusCode
  * @param string $statusDescription
  * @see HTTPResponse::__construct();
  */
 public function __construct($body = null, $statusCode = null, $statusDescription = null)
 {
     if ($body instanceof HTTPResponse) {
         // statusCode and statusDescription should override whatever is passed in the body
         if ($statusCode) {
             $body->setStatusCode($statusCode);
         }
         if ($statusDescription) {
             $body->setStatusDescription($statusDescription);
         }
         $this->setResponse($body);
     } else {
         $response = new HTTPResponse($body, $statusCode, $statusDescription);
         // Error responses should always be considered plaintext, for security reasons
         $response->addHeader('Content-Type', 'text/plain');
         $this->setResponse($response);
     }
     parent::__construct($this->getResponse()->getBody(), $this->getResponse()->getStatusCode());
 }
 /**
  * Determines if a specified file exists
  *
  * @param HTTPRequest $request
  * @return HTTPResponse
  */
 public function fileexists(HTTPRequest $request)
 {
     // Assert that requested filename doesn't attempt to escape the directory
     $originalFile = $request->requestVar('filename');
     if ($originalFile !== basename($originalFile)) {
         $return = array('error' => _t('File.NOVALIDUPLOAD', 'File is not a valid upload'));
     } else {
         $return = array('exists' => $this->checkFileExists($originalFile));
     }
     // Encode and present response
     $response = new HTTPResponse(Convert::raw2json($return));
     $response->addHeader('Content-Type', 'application/json');
     if (!empty($return['error'])) {
         $response->setStatusCode(400);
     }
     return $response;
 }