From 22c36c93584040a5a4113dfc86bb9e8dcf86cb25 Mon Sep 17 00:00:00 2001 From: zorn Date: Tue, 28 Mar 2017 12:54:53 +1000 Subject: [PATCH 1/3] Some fixes to get valid JSON in response --- lib/Doctrine/CouchDB/HTTP/SocketClient.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/CouchDB/HTTP/SocketClient.php b/lib/Doctrine/CouchDB/HTTP/SocketClient.php index fb4228a..7d463d4 100644 --- a/lib/Doctrine/CouchDB/HTTP/SocketClient.php +++ b/lib/Doctrine/CouchDB/HTTP/SocketClient.php @@ -290,12 +290,13 @@ public function request($method, $path, $data = null, $raw = false, array $heade while ($bytesLeft > 0) { $body .= $read = fread($this->connection, $bytesLeft + 2); $bytesLeft -= strlen($read); + $body = rtrim($body); } } } while ($bytesToRead > 0); // Chop off \r\n from the end. - $body = substr($body, 0, -2); + $body = rtrim($body); } // Reset the connection if the server asks for it. From aa0c8dcba58721ac788d7dc8437562cbfd33dd5a Mon Sep 17 00:00:00 2001 From: zorn Date: Thu, 27 Apr 2017 12:38:49 +1000 Subject: [PATCH 2/3] Avoid trimming something other than new line. --- lib/Doctrine/CouchDB/HTTP/SocketClient.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/CouchDB/HTTP/SocketClient.php b/lib/Doctrine/CouchDB/HTTP/SocketClient.php index 7d463d4..e044ec8 100644 --- a/lib/Doctrine/CouchDB/HTTP/SocketClient.php +++ b/lib/Doctrine/CouchDB/HTTP/SocketClient.php @@ -290,13 +290,13 @@ public function request($method, $path, $data = null, $raw = false, array $heade while ($bytesLeft > 0) { $body .= $read = fread($this->connection, $bytesLeft + 2); $bytesLeft -= strlen($read); - $body = rtrim($body); + $body = substr($body, 0, -2); } } } while ($bytesToRead > 0); // Chop off \r\n from the end. - $body = rtrim($body); + $body = substr($body, 0, -2); } // Reset the connection if the server asks for it. @@ -322,4 +322,3 @@ public function request($method, $path, $data = null, $raw = false, array $heade return new Response($headers['status'], $headers, $body, $raw); } } - From e688eb4aeba4a6a93531cd2d647c94b3f23a132a Mon Sep 17 00:00:00 2001 From: zorn Date: Thu, 27 Apr 2017 12:50:14 +1000 Subject: [PATCH 3/3] Removed unnecessary trim --- lib/Doctrine/CouchDB/HTTP/SocketClient.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/Doctrine/CouchDB/HTTP/SocketClient.php b/lib/Doctrine/CouchDB/HTTP/SocketClient.php index e044ec8..254e1f0 100644 --- a/lib/Doctrine/CouchDB/HTTP/SocketClient.php +++ b/lib/Doctrine/CouchDB/HTTP/SocketClient.php @@ -294,9 +294,6 @@ public function request($method, $path, $data = null, $raw = false, array $heade } } } while ($bytesToRead > 0); - - // Chop off \r\n from the end. - $body = substr($body, 0, -2); } // Reset the connection if the server asks for it.