diff --git a/Tranga/Server.cs b/Tranga/Server.cs index 9202858..17c2d2a 100644 --- a/Tranga/Server.cs +++ b/Tranga/Server.cs @@ -113,15 +113,23 @@ public partial class Server : GlobalBase if (!request.HasEntityBody) { Log("No request body"); - Dictionary emptyBody = new(); - return emptyBody; + return new Dictionary(); } Stream body = request.InputStream; Encoding encoding = request.ContentEncoding; - StreamReader reader = new StreamReader(body, encoding); - string s = reader.ReadToEnd(); - Dictionary requestBody = JsonConvert.DeserializeObject>(s); - return requestBody; + using StreamReader streamReader = new (body, encoding); + try + { + Dictionary requestBody = + JsonConvert.DeserializeObject>(streamReader.ReadToEnd()) + ?? new(); + return requestBody; + } + catch (JsonException e) + { + Log(e.Message); + } + return new Dictionary(); } private void HandleGet(HttpListenerRequest request, HttpListenerResponse response) diff --git a/Tranga/ServerV2.cs b/Tranga/ServerV2.cs index 423ad0c..48a11a2 100644 --- a/Tranga/ServerV2.cs +++ b/Tranga/ServerV2.cs @@ -1,7 +1,5 @@ using System.Net; -using System.Text; using System.Text.RegularExpressions; -using Newtonsoft.Json; namespace Tranga; @@ -29,30 +27,6 @@ public partial class Server SendResponse(responseMessage.Item1, response, responseMessage.Item2); } - private Dictionary GetRequestBody(HttpListenerRequest request) - { - if (!request.HasEntityBody) - { - Log("No request body"); - return new Dictionary(); - } - Stream body = request.InputStream; - Encoding encoding = request.ContentEncoding; - using StreamReader streamReader = new (body, encoding); - try - { - Dictionary requestBody = - JsonConvert.DeserializeObject>(streamReader.ReadToEnd()) - ?? new(); - return requestBody; - } - catch (JsonException e) - { - Log(e.Message); - } - return new Dictionary(); - } - private ValueTuple HandleGetV2(string path, HttpListenerResponse response, Dictionary requestParameters) {