Skip to content

Commit

Permalink
Fix HttpContextCookieService constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriyDurov committed Oct 28, 2024
1 parent 5936647 commit c7e95a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ internal class HttpContextCookieService : ICookieService

private IHeaderDictionary _responseHeaders { get; set; }

public HttpContextCookieService(IHttpContextAccessor httpContextAccessor, IFeatureCollection features, ILogger<ICookieService> logger)
public HttpContextCookieService(IHttpContextAccessor httpContextAccessor, ILogger<ICookieService> logger)
{
_httpContext = httpContextAccessor.HttpContext!;
_logger = logger;

_requestCookies = _httpContext.Request.Cookies
.Select(x => new Cookie(x.Key, x.Value)).ToDictionary(cookie => cookie.Key);

_responseHeaders = features.GetRequiredFeature<IHttpResponseFeature>().Headers;
_responseHeaders = _httpContext.Features.GetRequiredFeature<IHttpResponseFeature>().Headers;
}

public Task<IEnumerable<Cookie>> GetAllAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,16 @@ public async Task SetCookie_WhenDuplicate_ShouldOnlySetCookieOnce()
private static TestServices CreateTestServices()
{
var httpContext = new DefaultHttpContext();
var accessor = new TestHttpContextAccessor(httpContext);
var accessor = new HttpContextAccessor
{
HttpContext = httpContext
};
var logger = new LoggerFactory().CreateLogger<ICookieService>();

var cookieService = new HttpContextCookieService(accessor, httpContext.Features, logger);
var cookieService = new HttpContextCookieService(accessor, logger);

return new TestServices(httpContext, accessor, cookieService);
}

private record TestServices(HttpContext HttpContext, IHttpContextAccessor HttpContextAccessor, ICookieService CookieService);

private class TestHttpContextAccessor(HttpContext httpContext) : IHttpContextAccessor
{
private HttpContext? _httpContext = httpContext;

public HttpContext? HttpContext
{
get => _httpContext;
set => _httpContext = value;
}
}
}

0 comments on commit c7e95a1

Please sign in to comment.