diff --git a/DNSMadeEasy/driver/REST.php b/DNSMadeEasy/driver/REST.php index d95cbf2..4e77e10 100644 --- a/DNSMadeEasy/driver/REST.php +++ b/DNSMadeEasy/driver/REST.php @@ -183,7 +183,7 @@ private function send($command, $uriParameters, $method, $content = NULL) $info = curl_getinfo($ch); $request = new Request($info, $content); - $response = new Response($result, $info['total_time']); + $response = new Response($result, $info['total_time'], $method); //If debug mode is on, output the debug messages. if ($this->_config->getDebug()) { diff --git a/DNSMadeEasy/driver/Response.php b/DNSMadeEasy/driver/Response.php index 84294ee..2129db4 100644 --- a/DNSMadeEasy/driver/Response.php +++ b/DNSMadeEasy/driver/Response.php @@ -103,16 +103,25 @@ class Response 505 => 'HTTP Version Not Supported', ); + /** + * These methods won't receive a response body + * @var array + */ + private $_httpMethodsWithoutBody = array( + 'delete', + 'put', + ); + /** * Construct the driver response. * @param string $response The response containing the headers and body as a string. * @param float $timeTaken The time taken in seconds. */ - public function __construct($response, $timeTaken) + public function __construct($response, $timeTaken, $method = false) { $this->_timeTaken = $timeTaken; - $parsed = $this->parseMessage($response); + $parsed = $this->parseMessage($response, $method); $this->_rawHeaders = $parsed['headers']; $this->_body = trim($this->fixJSON($parsed['body'])); @@ -193,7 +202,7 @@ public function getRawHeaders() * @throws RESTException * @return array */ - private function parseMessage($message) + private function parseMessage($message, $method) { assert(is_string($message)); @@ -207,7 +216,11 @@ private function parseMessage($message) $border = strpos($message, $barrier); if ($border === false) { - throw new RESTException('Got an invalid response from the server.'); + if (in_array($method,$this->_httpMethodsWithoutBody)) { + $border = strlen($message); + } else { + throw new RESTException('Got an invalid response from the server.'); + } } $result = array();