From 32bb793b4b87c2227b2a12e6790bd092bd2e840d Mon Sep 17 00:00:00 2001 From: "Abdulmhsen B. A. A" Date: Thu, 3 Mar 2022 15:54:08 +0300 Subject: [PATCH] fixes for body parsing. --- src/Libs/Servers/EmbyServer.php | 2 +- src/Libs/Servers/JellyfinServer.php | 8 +++----- src/Libs/Servers/PlexServer.php | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Libs/Servers/EmbyServer.php b/src/Libs/Servers/EmbyServer.php index 0b0b0c7b..166098af 100644 --- a/src/Libs/Servers/EmbyServer.php +++ b/src/Libs/Servers/EmbyServer.php @@ -61,7 +61,7 @@ class EmbyServer extends JellyfinServer return $request; } - $payload = ag($request->getParsedBody(), 'data', null); + $payload = ag($request->getParsedBody() ?? [], 'data', null); if (null === $payload || null === ($json = json_decode((string)$payload, true))) { return $request; diff --git a/src/Libs/Servers/JellyfinServer.php b/src/Libs/Servers/JellyfinServer.php index 5f1bacab..2a40a541 100644 --- a/src/Libs/Servers/JellyfinServer.php +++ b/src/Libs/Servers/JellyfinServer.php @@ -16,7 +16,6 @@ use Closure; use DateTimeInterface; use JsonException; use JsonMachine\Items; -use Nyholm\Psr7\Stream; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\UriInterface; use Psr\Log\LoggerInterface; @@ -123,13 +122,12 @@ class JellyfinServer implements ServerInterface $body = $request->getBody()->getContents(); - // -- re-attach body to request. - $request = $request->withBody(Stream::create($body)); - if (null === ($json = json_decode($body, true))) { return $request; } + $request = $request->withParsedBody($json); + $attributes = [ 'SERVER_ID' => ag($json, 'ServerId', ''), 'SERVER_NAME' => ag($json, 'ServerName', ''), @@ -147,7 +145,7 @@ class JellyfinServer implements ServerInterface public function parseWebhook(ServerRequestInterface $request): StateInterface { - if (null === ($json = json_decode($request->getBody()->getContents(), true))) { + if (null === ($json = $request->getParsedBody())) { throw new HttpException(sprintf('%s: No payload.', afterLast(__CLASS__, '\\')), 400); } diff --git a/src/Libs/Servers/PlexServer.php b/src/Libs/Servers/PlexServer.php index 840fb8f1..df600533 100644 --- a/src/Libs/Servers/PlexServer.php +++ b/src/Libs/Servers/PlexServer.php @@ -119,7 +119,7 @@ class PlexServer implements ServerInterface return $request; } - $payload = ag($request->getParsedBody(), 'payload', null); + $payload = ag($request->getParsedBody() ?? [], 'payload', null); if (null === $payload || null === ($json = json_decode((string)$payload, true))) { return $request;