Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit d7e0a75

Browse files
committed
Fix chunked transfer encoding problems due to trailing whitespace.
1 parent ba8b5c0 commit d7e0a75

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/Doctrine/CouchDB/HTTP/SocketClient.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ public function request($method, $path, $data = null, $raw = false, array $heade
269269
// Read body only as specified by chunk sizes, everything else
270270
// are just footnotes, which are not relevant for us.
271271
while ($bytesToRead > 0) {
272-
$body .= $read = fgets($this->connection, $bytesToRead + 1);
272+
$read = fgets($this->connection, $bytesToRead + 1);
273+
// Chop off \r\n from the end.
274+
$body .= rtrim($read);
273275
$bytesToRead -= strlen($read);
274276
}
275277
} else {
@@ -288,14 +290,13 @@ public function request($method, $path, $data = null, $raw = false, array $heade
288290
// are just footnotes, which are not relevant for us.
289291
$bytesLeft = $bytesToRead;
290292
while ($bytesLeft > 0) {
291-
$body .= $read = fread($this->connection, $bytesLeft + 2);
293+
$read = fread($this->connection, $bytesLeft + 2);
294+
// Chop off \r\n from the end.
295+
$body .= rtrim($read);
292296
$bytesLeft -= strlen($read);
293297
}
294298
}
295299
} while ($bytesToRead > 0);
296-
297-
// Chop off \r\n from the end.
298-
$body = substr($body, 0, -2);
299300
}
300301

301302
// Reset the connection if the server asks for it.

0 commit comments

Comments
 (0)