From 568b0a48fefc057530bcc979d5453f80e43d8df6 Mon Sep 17 00:00:00 2001 From: Lucca Faria Ferri Date: Mon, 30 Jan 2023 07:03:36 -0800 Subject: [PATCH] quick fix errorwhen parsing invalid http header --- src/DiIiS-NA/REST/Http/Http.cs | 40 ++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/DiIiS-NA/REST/Http/Http.cs b/src/DiIiS-NA/REST/Http/Http.cs index 837a63a..ed04903 100644 --- a/src/DiIiS-NA/REST/Http/Http.cs +++ b/src/DiIiS-NA/REST/Http/Http.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; +using DiIiS_NA.Core.Logging; namespace DiIiS_NA.REST.Http { @@ -87,27 +88,34 @@ namespace DiIiS_NA.REST.Http while (!sr.EndOfStream) { - info = sr.ReadLine().Split(new string[] { ": " }, StringSplitOptions.RemoveEmptyEntries); - - if (info.Length == 2) - headerValues.Add(info[0].Replace("-", "").ToLower(), info[1]); - else if (info.Length > 2) + try { - var val = ""; + info = sr.ReadLine().Split(new string[] { ": " }, StringSplitOptions.RemoveEmptyEntries); - info.Skip(1); + if (info.Length == 2) + headerValues.Add(info[0].Replace("-", "").ToLower(), info[1]); + else if (info.Length > 2) + { + var val = ""; - headerValues.Add(info[0].Replace("-", "").ToLower(), val); + info.Skip(1); + + headerValues.Add(info[0].Replace("-", "").ToLower(), val); + } + else + { + // We are at content here. + var content = sr.ReadLine(); + + headerValues.Add("content", content); + + // There shouldn't be anything after the content! + break; + } } - else + catch (Exception ex) { - // We are at content here. - var content = sr.ReadLine(); - - headerValues.Add("content", content); - - // There shouldn't be anything after the content! - break; + return null; } } }