/**
  * @since  1.0
  *
  * @param HttpRequest $httpRequest
  */
 public function __construct(HttpRequest $httpRequest)
 {
     $errorCode = $httpRequest->getLastErrorCode();
     switch ($errorCode) {
         case 22:
             //	equals CURLE_HTTP_RETURNED_ERROR but this constant is not defined in PHP
             $httpCode = $httpRequest->getLastTransferInfo(CURLINFO_HTTP_CODE);
             $message = "HTTP request ended with {$httpCode} code\n";
             break;
         default:
             $message = $httpRequest->getLastError();
     }
     parent::__construct($message, $errorCode);
 }
 /**
  * Execute a HTTP-based SPARQL POST request according to
  * http://www.w3.org/2009/sparql/docs/http-rdf-update/.
  * The method throws exceptions based on
  * GenericHttpDatabaseConnector::mapHttpRequestError(). If errors occur and this
  * method does not throw anything, then an empty result with an error
  * code is returned.
  *
  * @note This protocol is not part of the SPARQL standard and may not
  * be supported by all stores. To avoid using it, simply do not provide
  * a data endpoint URL when configuring the SPARQL database. If used,
  * the protocol might lead to a better performance since there is less
  * parsing required to fetch the data from the request.
  * @note Some stores (e.g. 4Store) support another mode of posting data
  * that may be implemented in a special database handler.
  *
  * @param $payload string Turtle serialization of data to send
  *
  * @return boolean
  */
 public function doHttpPost($payload)
 {
     if ($this->repositoryClient->getDataEndpoint() === '') {
         throw new BadHttpDatabaseResponseException(BadHttpDatabaseResponseException::ERROR_NOSERVICE, "SPARQL POST with data: {$payload}", 'not specified');
     }
     $defaultGraph = $this->repositoryClient->getDefaultGraph();
     $this->httpRequest->setOption(CURLOPT_URL, $this->repositoryClient->getDataEndpoint() . ($defaultGraph !== '' ? '?graph=' . urlencode($defaultGraph) : '?default'));
     $this->httpRequest->setOption(CURLOPT_POST, true);
     // POST as file (fails in 4Store)
     $payloadFile = tmpfile();
     fwrite($payloadFile, $payload);
     fseek($payloadFile, 0);
     $this->httpRequest->setOption(CURLOPT_INFILE, $payloadFile);
     $this->httpRequest->setOption(CURLOPT_INFILESIZE, strlen($payload));
     $this->httpRequest->setOption(CURLOPT_HTTPHEADER, array('Content-Type: application/x-turtle'));
     $this->httpRequest->execute();
     if ($this->httpRequest->getLastErrorCode() == 0) {
         return true;
     }
     // TODO The error reporting based on SPARQL (Update) is not adequate for the HTTP POST protocol
     $this->mapHttpRequestError($this->repositoryClient->getDataEndpoint(), $payload);
     return false;
 }