Skip to content

Commit c6ef990

Browse files
committed
Introduce response_type for Fetch module
1 parent da461f9 commit c6ef990

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

app/core/Fetch.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ final class Fetch {
1515
// In case if not supported we use raw
1616
protected string $request_type = 'raw';
1717

18+
// Type of the response can be one of json, msgpack, binary, raw
19+
protected string $response_type = 'raw';
20+
1821
// Array containing proxy info with next fields
1922
/** @var array{host:string,port:int,user?:string,password?:string,type?:string} */
2023
protected array $request_proxy = [];
@@ -50,7 +53,7 @@ public static function new(array $config = []): self {
5053
};
5154
}
5255
if (!isset($Self->decoder_fn)) {
53-
$Self->decoder_fn = match ($Self->request_type) {
56+
$Self->decoder_fn = match ($Self->response_type) {
5457
'msgpack' => msgpack_unpack(...),
5558
'json' => fn($response) => json_decode($response = preg_replace('/"\s*:\s*([0-9]+\.[0-9]+)([,\}\]])/ius', '":"$1"$2', $response), true, flags: JSON_BIGINT_AS_STRING),
5659
default => fn($response) => $response,

0 commit comments

Comments
 (0)