Skip to content

Commit

Permalink
reduce code smells
Browse files Browse the repository at this point in the history
  • Loading branch information
Burak Akgerman committed Jun 4, 2022
1 parent bda53be commit 9d94fc2
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/Shared/LayoutRenderers/AspNetResponseCookieLayoutRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ private List<string> GetCookieNames(HttpCookieCollection cookies)

private IEnumerable<KeyValuePair<string, string>> GetCookieValues(HttpCookieCollection cookies, bool checkForExclude)
{
var response = new List<KeyValuePair<string, string>>();
var cookieNames = GetCookieNames(cookies);
foreach (var cookieName in cookieNames)
{
Expand All @@ -115,26 +116,31 @@ private IEnumerable<KeyValuePair<string, string>> GetCookieValues(HttpCookieColl
{
continue;
}
response.AddRange(GetCookieValue(httpCookie,cookieName));
}
return response;
}

if (OutputFormat != AspNetRequestLayoutOutputFormat.Flat)
private IEnumerable<KeyValuePair<string, string>> 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<string, string>(cookieKey, httpCookie.Values[multiValueKey]);
cookieKey = cookieName;
isFirst = false;
}
yield return new KeyValuePair<string, string>(cookieKey, httpCookie.Values[multiValueKey]);
}
else
{
yield return new KeyValuePair<string, string>(cookieName, httpCookie.Value);
}
}
else
{
yield return new KeyValuePair<string, string>(cookieName, httpCookie.Value);
}
}

Expand All @@ -144,7 +150,7 @@ private IEnumerable<KeyValuePair<string, string>> GetCookieValues(HttpCookieColl
/// </summary>
/// <param name="response"></param>
/// <returns></returns>
protected IList<SetCookieHeaderValue> GetCookies(HttpResponse response)
protected static IList<SetCookieHeaderValue> GetCookies(HttpResponse response)
{
var queryResults = response.Headers[HeaderNames.SetCookie];
if (queryResults.Count > 0 && SetCookieHeaderValue.TryParseList(queryResults, out var result))
Expand Down

0 comments on commit 9d94fc2

Please sign in to comment.