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

Some fixes to get valid JSON in response #74

wants to merge 3 commits into from

Conversation

zorn-v
Copy link

@zorn-v zorn-v commented Mar 28, 2017

No description provided.

@damiankloip
Copy link
Contributor

@zorn-v what's the reason for trimming inside the while() loop and after it?

@zorn-v
Copy link
Author

zorn-v commented Apr 27, 2017

Don't know purpose for last trim, just replace ugly analog 😄
In loop its need to fix JSON response like this

{"key": "long value 
that wrap beetween chunks"}

That JSON become invalid

@@ -290,6 +290,7 @@ 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.

@zorn-v zorn-v closed this Dec 21, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants