From 75bd726fab3269b956e9fa5f6d3874abd9c75179 Mon Sep 17 00:00:00 2001 From: Andrii Voznesenskyi Date: Mon, 30 Sep 2024 01:56:47 +0200 Subject: [PATCH] (#14) nuar: test ussage of messagePack [pack-all-force] --- src/Nuar/src/Nuar/Nuar.csproj | 2 ++ .../src/Nuar/Requests/PayloadTransformer.cs | 31 +++++++++---------- .../obj/Debug/net9.0/Nuar.AssemblyInfo.cs | 2 +- .../net9.0/Nuar.AssemblyInfoInputs.cache | 2 +- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/Nuar/src/Nuar/Nuar.csproj b/src/Nuar/src/Nuar/Nuar.csproj index 8f388b7..d00c8ff 100644 --- a/src/Nuar/src/Nuar/Nuar.csproj +++ b/src/Nuar/src/Nuar/Nuar.csproj @@ -36,6 +36,8 @@ + + diff --git a/src/Nuar/src/Nuar/Requests/PayloadTransformer.cs b/src/Nuar/src/Nuar/Requests/PayloadTransformer.cs index 14b92f5..79f5d9d 100644 --- a/src/Nuar/src/Nuar/Requests/PayloadTransformer.cs +++ b/src/Nuar/src/Nuar/Requests/PayloadTransformer.cs @@ -3,7 +3,7 @@ using System.Linq; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; -using NetJSON; +using MessagePack; using Nuar.Options; using Route = Nuar.Configuration.Route; @@ -27,20 +27,11 @@ public PayloadTransformer(NuarOptions options, IPayloadManager payloadManager, I public bool HasTransformations(string resourceId, Route route) { - // Check if the resource ID exists - if (!string.IsNullOrWhiteSpace(resourceId)) - { - return true; - } + // Skip payload processing for GET requests or routes without transformation + if (route.Method.ToLowerInvariant() == "get") + return false; - // Check if route binds exist - if (route.Bind != null && route.Bind.Any()) - { - return true; - } - - // Check if there are any transformations - if (route.Transform != null && route.Transform.Any()) + if (!string.IsNullOrWhiteSpace(resourceId) || route.Bind != null && route.Bind.Any() || route.Transform != null && route.Transform.Any()) { return true; } @@ -51,6 +42,12 @@ public bool HasTransformations(string resourceId, Route route) public PayloadSchema Transform(string payload, string resourceId, Route route, HttpRequest request, RouteData data) { + // Skip transformation for GET requests + if (route.Method.ToLowerInvariant() == "get") + { + return null; + } + var payloadKey = GetPayloadKey(route); var command = _payloads.ContainsKey(payloadKey) ? GetObjectFromPayload(route, payload) @@ -111,7 +108,7 @@ public PayloadSchema Transform(string payload, string resourceId, Route route, H private object GetObjectFromPayload(Route route, string content) { var payloadValue = _payloads[GetPayloadKey(route)].Payload; - var request = NetJSON.NetJSON.Deserialize(payloadValue.GetType(), content); + var request = MessagePackSerializer.Deserialize(payloadValue.GetType(), System.Text.Encoding.UTF8.GetBytes(content)); var payloadValues = (IDictionary)payloadValue; var requestValues = (IDictionary)request; @@ -130,8 +127,8 @@ private object GetObjectFromPayload(Route route, string content) private static object GetObject(string content) { - // Deserialize directly to an ExpandoObject using NetJSON - return NetJSON.NetJSON.Deserialize(content); + // Deserialize directly to an ExpandoObject using MessagePack + return MessagePackSerializer.Deserialize(System.Text.Encoding.UTF8.GetBytes(content)); } private string GetPayloadKey(Route route) diff --git a/src/Nuar/src/Nuar/obj/Debug/net9.0/Nuar.AssemblyInfo.cs b/src/Nuar/src/Nuar/obj/Debug/net9.0/Nuar.AssemblyInfo.cs index 488c4cc..4c2cd98 100644 --- a/src/Nuar/src/Nuar/obj/Debug/net9.0/Nuar.AssemblyInfo.cs +++ b/src/Nuar/src/Nuar/obj/Debug/net9.0/Nuar.AssemblyInfo.cs @@ -15,7 +15,7 @@ [assembly: System.Reflection.AssemblyCopyrightAttribute("ITSharpPro © ")] [assembly: System.Reflection.AssemblyDescriptionAttribute("Nuar - A framework for building API gateways in a microservices architecture")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+98aec01653883b77d79363dc0cb9c8642aed0ee1")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+1c267071c9e105f917ff8b6455cddb0d8d968c41")] [assembly: System.Reflection.AssemblyProductAttribute("Nuar")] [assembly: System.Reflection.AssemblyTitleAttribute("Nuar")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/src/Nuar/src/Nuar/obj/Debug/net9.0/Nuar.AssemblyInfoInputs.cache b/src/Nuar/src/Nuar/obj/Debug/net9.0/Nuar.AssemblyInfoInputs.cache index 73cc7de..e94b58a 100644 --- a/src/Nuar/src/Nuar/obj/Debug/net9.0/Nuar.AssemblyInfoInputs.cache +++ b/src/Nuar/src/Nuar/obj/Debug/net9.0/Nuar.AssemblyInfoInputs.cache @@ -1 +1 @@ -f5657c688c2db74647cbb018bce61daf836b7962dd555a348e867b98a4cf9c62 +b5fc7bfd25e567d26982fac35ae5267766c22f5a82928e0604d6141a51e6344e