public void Process(HttpResponseMessage httpResponseMessage) { var headers = new Dictionary <string, int>(); foreach (var header in httpResponseMessage?.Headers.Where(x => x.Key == HeaderNames.SetCookie)) { foreach (var headerValue in header.Value) { var cookieSettings = setCookieParser.Parse(headerValue); var cookieKey = cookieSettings.Key; var prefix = headerRenamerService.Rename(cookieKey) ? pathLocator.GetPath() : string.Empty; var cookieKeyWithPrefix = string.Concat(prefix, cookieKey); var allowedHeaderCount = headerCountService.Count(cookieKey); var currentHeaderCount = GetHeaderCount(headers, cookieKey); var cookieValue = cookieSettings.Value; if (cookieSettings.Key == Constants.DfcSession) { cookieValue = compositeDataProtectionDataProvider.Protect(cookieValue); } if (currentHeaderCount < allowedHeaderCount) { RegisterHeader(headers, cookieKey); httpContextAccessor.HttpContext.Response.Cookies.Append(cookieKeyWithPrefix, cookieValue, cookieSettings.CookieOptions); AddToHttpContext(cookieKeyWithPrefix, cookieValue); } } } }
public void CanCount(string headerValue, int expectedHeaderCount) { Assert.Equal(expectedHeaderCount, headerCountService.Count(headerValue)); }