diff --git a/CloudFlareUtilities/ClearanceHandler.cs b/CloudFlareUtilities/ClearanceHandler.cs index d2d37f9..b17f3fe 100644 --- a/CloudFlareUtilities/ClearanceHandler.cs +++ b/CloudFlareUtilities/ClearanceHandler.cs @@ -74,7 +74,7 @@ protected override void Dispose(bool disposing) /// The task object representing the asynchronous operation. protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { - var IdCookieBefore = ClientHandler.CookieContainer.GetCookiesByName(request.RequestUri, IdCookieName).FirstOrDefault(); + var idCookieBefore = ClientHandler.CookieContainer.GetCookiesByName(request.RequestUri, IdCookieName).FirstOrDefault(); var clearanceCookieBefore = ClientHandler.CookieContainer.GetCookiesByName(request.RequestUri, ClearanceCookieName).FirstOrDefault(); EnsureClientHeader(request); @@ -99,13 +99,13 @@ protected override async Task SendAsync(HttpRequestMessage if (IsClearanceRequired(response)) throw new CloudFlareClearanceException(retries); - var IdCookieAfter = ClientHandler.CookieContainer.GetCookiesByName(request.RequestUri, IdCookieName).FirstOrDefault(); + var idCookieAfter = ClientHandler.CookieContainer.GetCookiesByName(request.RequestUri, IdCookieName).FirstOrDefault(); var clearanceCookieAfter = ClientHandler.CookieContainer.GetCookiesByName(request.RequestUri, ClearanceCookieName).FirstOrDefault(); // inject set-cookie headers in case the cookies changed - if (IdCookieAfter != null && IdCookieAfter != IdCookieBefore) + if (idCookieAfter != null && idCookieAfter != idCookieBefore) { - response.Headers.Add(HttpHeader.SetCookie, IdCookieAfter.ToHeaderValue()); + response.Headers.Add(HttpHeader.SetCookie, idCookieAfter.ToHeaderValue()); } if (clearanceCookieAfter != null && clearanceCookieAfter != clearanceCookieBefore) { @@ -167,8 +167,7 @@ private async Task PassClearance(HttpResponseMessage response, CancellationToken var clearanceRequest = new HttpRequestMessage(HttpMethod.Get, clearanceUri); - IEnumerable userAgent; - if (response.RequestMessage.Headers.TryGetValues(HttpHeader.UserAgent, out userAgent)) + if (response.RequestMessage.Headers.TryGetValues(HttpHeader.UserAgent, out var userAgent)) clearanceRequest.Headers.Add(HttpHeader.UserAgent, userAgent); var passResponse = await _client.SendAsync(clearanceRequest, cancellationToken).ConfigureAwait(false); @@ -180,9 +179,10 @@ private void SaveIdCookie(HttpResponseMessage response) var cookies = response.Headers .Where(pair => pair.Key == HttpHeader.SetCookie) .SelectMany(pair => pair.Value) - .Where(cookie => cookie.StartsWith($"{IdCookieName}=")); + .Where(cookie => cookie.StartsWith($"{IdCookieName}=")) + .ToList(); - if (cookies.Count() == 0) + if (!cookies.Any()) return; // Expire any old cloudflare cookies. diff --git a/CloudFlareUtilities/HttpMessageHandlerExtensions.cs b/CloudFlareUtilities/HttpMessageHandlerExtensions.cs index 521cd83..5074817 100644 --- a/CloudFlareUtilities/HttpMessageHandlerExtensions.cs +++ b/CloudFlareUtilities/HttpMessageHandlerExtensions.cs @@ -6,8 +6,9 @@ internal static class HttpMessageHandlerExtensions { public static HttpMessageHandler GetMostInnerHandler(this HttpMessageHandler self) { - var delegatingHandler = self as DelegatingHandler; - return delegatingHandler == null ? self : delegatingHandler.InnerHandler.GetMostInnerHandler(); + return self is DelegatingHandler handler + ? handler.InnerHandler.GetMostInnerHandler() + : self; } } } \ No newline at end of file