/** * @covers DNSMadeEasy\debug\Debugger::response */ public function testResponseWithFailure() { $response = "HTTP/1.1 400 Bad Request\r\nServer: Apache-Coyote/1.1\r\nx-dnsme-requestId: 918f36f1-45f1-4bdc-8d55-a6f26a3db73b\r\nx-dnsme-requestsRemaining: 148\r\nx-dnsme-requestLimit: 150\r\nSet-Cookie: JSESSIONID=3CC6DB92E45AD918WS894TSDDC67EF47; Path=/V2.0/; HttpOnly\r\nContent-Type: application/json\r\nTransfer-Encoding: chunked\r\nDate: Wed, 22 May 2013 06:37:08 GMT\r\n\r\n\nBad Request"; $response = new Response($response, 1.2); $this->setOutputCallback(function ($output) { $this->assertInternalType('string', $output); }); //Fire off the debug request $this->debugger->response($response); }
/** * Sends the request to the server. * @param string $command The URI to append after the base URL. * @param array $uriParameters An optional array of URI template parameters. * @param string $method The request method. * @param string $content The request body. * @throws RESTException * @return \DNSMadeEasy\Result */ private function send($command, $uriParameters, $method, $content = NULL) { $url = $this->_config->getURL(); $ch = curl_init($url . $this->_uriTemplate->expand($command, $uriParameters)); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 300); curl_setopt($ch, CURLOPT_HTTPHEADER, $this->getAuthenticationHeaders()); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if ($content !== NULL) { curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($content)); } switch (strtolower($method)) { case "get": curl_setopt($ch, CURLOPT_HTTPGET, true); break; case "post": curl_setopt($ch, CURLOPT_POST, true); break; case "put": curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); //CURL_OPTPUT requires INFILE and writing to ram/disk, which is annoying break; case "delete": curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); break; } curl_setopt($ch, CURLINFO_HEADER_OUT, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); if (true || $this->_config->usingSandbox()) { //TODO le true ajouté par DDC pour bypass le control curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //Temporary workaround because https://api.sandbox.dnsmadeeasy.com uses a bad certificate curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); } else { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); } $result = curl_exec($ch); //Something bad has happened, for example the API is down, etc. if (curl_errno($ch)) { $errorNumber = curl_errno($ch); $error = curl_error($ch); throw new RESTException("Error: {$errorNumber} - {$error}"); } $info = curl_getinfo($ch); $request = new Request($info, $content); $response = new Response($result, $info['total_time']); //If debug mode is on, output the debug messages. if ($this->_config->getDebug()) { $this->_debugger->request($request); $this->_debugger->response($response); } curl_close($ch); return new Result($response); }