nategood / httpful

A Chainable, REST Friendly, PHP HTTP Client. A sane alternative to cURL.
MIT License
1.74k stars 299 forks source link

Gerrit REST from AOSP #207

Open miroslavign opened 9 years ago

miroslavign commented 9 years ago

As stated in the documentation on: https://gerrit-review.googlesource.com/Documentation/rest-api.html "To prevent against Cross Site Script Inclusion (XSSI) attacks, the JSON response body starts with a magic prefix line that must be stripped before feeding the rest of the response body to a JSON parser:"

So, getting content from: https://android-review.googlesource.com/changes/?q=limit:2+q=status:merged&o=CURRENT_REVISION

presents an error.

It would be nice to have some sort of "skip n-chars" from body in order to have a correct JSON. I fixed it by just adding a patch in stripBom function in MimeHandlerAdapter.php : $body = substr($body,4); // cut )]}' and building it to .phar which I use.

However, I am no php developer, so I feel there should be a cleaner way, and cover wider-case scenarios.

hskrtich commented 8 years ago

You can do the same thing with a custom parser.

$response = \Httpful\Request::get($url)
    ->parseWith(function($body) {
        return json_decode(substr($body, 4));
    })
    ->send();