Skip to content

Commit

Permalink
Merge pull request #10 from pablohaedo/fixPutRequests
Browse files Browse the repository at this point in the history
Fixes responses empty body on put requests
  • Loading branch information
F21 committed Oct 5, 2019
2 parents d55a186 + 3da5858 commit d02b132
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DNSMadeEasy/driver/REST.php
Expand Up @@ -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()) {
Expand Down
21 changes: 17 additions & 4 deletions DNSMadeEasy/driver/Response.php
Expand Up @@ -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']));
Expand Down Expand Up @@ -193,7 +202,7 @@ public function getRawHeaders()
* @throws RESTException
* @return array
*/
private function parseMessage($message)
private function parseMessage($message, $method)
{
assert(is_string($message));

Expand All @@ -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();
Expand Down

0 comments on commit d02b132

Please sign in to comment.