diff --git a/src/Backends/Emby/Action/InspectRequest.php b/src/Backends/Emby/Action/InspectRequest.php index 38723f13..4e57973c 100644 --- a/src/Backends/Emby/Action/InspectRequest.php +++ b/src/Backends/Emby/Action/InspectRequest.php @@ -36,16 +36,12 @@ class InspectRequest return $this->tryResponse( context: $context, fn: function () use ($request) { - $userAgent = ag($request->getServerParams(), 'HTTP_USER_AGENT', ''); - - if (false === str_starts_with($userAgent, 'Emby Server/')) { - return new Response(status: false); + if (null === ($payload = ag($request->getParsedBody() ?? [], 'data', null))) { + return new Response(status: false, response: $request); } - $payload = (string)ag($request->getParsedBody() ?? [], 'data', null); - $json = json_decode( - json: $payload, + json: (string)$payload, associative: true, flags: JSON_INVALID_UTF8_IGNORE | JSON_THROW_ON_ERROR ); @@ -56,8 +52,8 @@ class InspectRequest 'backend' => [ 'id' => ag($json, 'Server.Id', ''), 'name' => ag($json, 'Server.Name'), - 'client' => before($userAgent, '/'), - 'version' => ag($json, 'Server.Version', fn() => afterLast($userAgent, '/')), + 'client' => 'Emby', + 'version' => ag($json, 'Server.Version', ''), ], 'user' => [ 'id' => ag($json, 'User.Id', ''), diff --git a/src/Libs/Initializer.php b/src/Libs/Initializer.php index 897e549f..b87cd18e 100644 --- a/src/Libs/Initializer.php +++ b/src/Libs/Initializer.php @@ -260,12 +260,12 @@ final class Initializer // -- Forward requests to API server. if (true === str_starts_with($requestPath, Config::get('api.prefix', '????'))) { - return $this->defaultAPIServer($realRequest); + return $this->defaultAPIServer(clone $realRequest); } // -- Save request payload. if (true === Config::get('webhook.dumpRequest')) { - saveRequestPayload($realRequest); + saveRequestPayload(clone $realRequest); } $apikey = ag($realRequest->getQueryParams(), 'apikey', $realRequest->getHeaderLine('x-apikey')); @@ -384,7 +384,8 @@ final class Initializer $request, $loglevel ?? Level::Error, $this->formatLog($request, $response, $message), - ['messages' => $log], + ['messages' => $log, 'attr' => $attr ?? []], + forceContext: true ); return $response;