From 32bbec81fe55f5f9774cfc08bcdf9db5852a00fd Mon Sep 17 00:00:00 2001 From: pezcurrel Date: Thu, 31 Oct 2024 20:26:21 +0100 Subject: [PATCH] =?UTF-8?q?Fixed=20a=20check=20on=20json=20validity=20that?= =?UTF-8?q?=20was=20wrongly=20against=20=E2=80=9Cfalse=E2=80=9D=20instead?= =?UTF-8?q?=20of=20=E2=80=9Cnull=E2=80=9D;=20minor=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/httpjson.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/httpjson.php b/lib/httpjson.php index 170f1bd..e803c79 100644 --- a/lib/httpjson.php +++ b/lib/httpjson.php @@ -9,14 +9,14 @@ function httpjson($endpoint,$timeout=null,$method=null,$postdata=null,$accept=nu 'http'=>[ 'timeout'=>$timeout, 'method'=>$method, - 'user_agent'=>'Mozilla/5.0 (X11; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0', + 'user_agent'=>'httpjson/1.1', 'header'=>"Accept: {$accept}\r\n", 'ignore_errors'=>true ] ]; if (!is_null($token)) $context['http']['header'].="Authorization: Bearer {$token}\r\n"; if (!is_null($postdata)) { - $context['http']['header'].="Content-type: application/x-www-form-urlencoded\r\n"; + $context['http']['header'].="Content-type: application/x-www-form-urlencoded\r\nIdempotency-Key: ".md5(implode('-',$postdata).time())."\r\n"; $context['http']['content']=http_build_query($postdata); } $context=stream_context_create($context); @@ -46,7 +46,7 @@ function httpjson($endpoint,$timeout=null,$method=null,$postdata=null,$accept=nu $errors[]="«got no headers"; } $res=@json_decode($res,true); - if ($res===false) { + if (is_null($res)) { $errors[]="got no valid JSON"; } else { if (count($errors)>0 && isset($res['error']))