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

Some fixes to get valid JSON in response #74

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions lib/Doctrine/CouchDB/HTTP/SocketClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,10 @@ 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 = substr($body, 0, -2);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After review I'm understand that trimming is not good idea. In 2 line above we read 2 additional symbols and we need to trim they only.
Otherwise it may trim spaces/tabs/etc that actualy was in that json.

}
}
} while ($bytesToRead > 0);

// Chop off \r\n from the end.
$body = substr($body, 0, -2);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already removed that symbols in while loop, and there we just make JSON become invalid again.

}

// Reset the connection if the server asks for it.
Expand All @@ -321,4 +319,3 @@ public function request($method, $path, $data = null, $raw = false, array $heade
return new Response($headers['status'], $headers, $body, $raw);
}
}