From 9d94fc26421588e7f3f3915b6608b24b1914e31d Mon Sep 17 00:00:00 2001 From: Burak Akgerman Date: Sat, 4 Jun 2022 19:58:11 -0400 Subject: [PATCH] reduce code smells --- .../AspNetResponseCookieLayoutRenderer.cs | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/Shared/LayoutRenderers/AspNetResponseCookieLayoutRenderer.cs b/src/Shared/LayoutRenderers/AspNetResponseCookieLayoutRenderer.cs index 6eb4e125..f18daa64 100644 --- a/src/Shared/LayoutRenderers/AspNetResponseCookieLayoutRenderer.cs +++ b/src/Shared/LayoutRenderers/AspNetResponseCookieLayoutRenderer.cs @@ -104,6 +104,7 @@ private List GetCookieNames(HttpCookieCollection cookies) private IEnumerable> GetCookieValues(HttpCookieCollection cookies, bool checkForExclude) { + var response = new List>(); var cookieNames = GetCookieNames(cookies); foreach (var cookieName in cookieNames) { @@ -115,26 +116,31 @@ private IEnumerable> GetCookieValues(HttpCookieColl { continue; } + response.AddRange(GetCookieValue(httpCookie,cookieName)); + } + return response; + } - if (OutputFormat != AspNetRequestLayoutOutputFormat.Flat) + private IEnumerable> GetCookieValue(HttpCookie httpCookie, string cookieName) + { + if (OutputFormat != AspNetRequestLayoutOutputFormat.Flat) + { + // Split multi-valued cookie, as allowed for in the HttpCookie API for backwards compatibility with classic ASP + var isFirst = true; + foreach (var multiValueKey in httpCookie.Values.AllKeys) { - // Split multi-valued cookie, as allowed for in the HttpCookie API for backwards compatibility with classic ASP - var isFirst = true; - foreach (var multiValueKey in httpCookie.Values.AllKeys) + var cookieKey = multiValueKey; + if (isFirst) { - var cookieKey = multiValueKey; - if (isFirst) - { - cookieKey = cookieName; - isFirst = false; - } - yield return new KeyValuePair(cookieKey, httpCookie.Values[multiValueKey]); + cookieKey = cookieName; + isFirst = false; } + yield return new KeyValuePair(cookieKey, httpCookie.Values[multiValueKey]); } - else - { - yield return new KeyValuePair(cookieName, httpCookie.Value); - } + } + else + { + yield return new KeyValuePair(cookieName, httpCookie.Value); } } @@ -144,7 +150,7 @@ private IEnumerable> GetCookieValues(HttpCookieColl /// /// /// - protected IList GetCookies(HttpResponse response) + protected static IList GetCookies(HttpResponse response) { var queryResults = response.Headers[HeaderNames.SetCookie]; if (queryResults.Count > 0 && SetCookieHeaderValue.TryParseList(queryResults, out var result))