Skip to content

Commit 2b45b20

Browse files
IfnotFrthilanga
authored andcommitted
Fix Http Response parsing laravel jsonp content (dingo#1357)
* Fix Http Response parsing laravel jsonp content * Fix Style CI
1 parent f942dfc commit 2b45b20

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Http/Response.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,16 @@ public static function makeFromExisting(IlluminateResponse $old)
9595
*/
9696
public static function makeFromJson(JsonResponse $json)
9797
{
98-
$new = static::create(json_decode($json->getContent(), true), $json->getStatusCode());
98+
$content = $json->getContent();
99+
100+
// If the contents of the JsonResponse does not starts with /**/ (typical laravel jsonp response)
101+
// we assume that it is a valid json response that can be decoded, or we just use the raw jsonp
102+
// contents for building the response
103+
if (! starts_with($json->getContent(), '/**/')) {
104+
$content = json_decode($json->getContent(), true);
105+
}
106+
107+
$new = static::create($content, $json->getStatusCode());
99108

100109
$new->headers = $json->headers;
101110

0 commit comments

Comments
 (0)