<commit_before>﻿using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using FilterLists.Agent.Core.List;
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;

namespace FilterLists.Agent.Infrastructure
{
    [UsedImplicitly]
    public class ListRepository : IListRepository
    {
        private readonly HttpClient _httpClient;
        private readonly ILogger<ListRepository> _logger;

        public ListRepository(HttpClient httpClient, ILogger<ListRepository> logger)
        {
            httpClient.Timeout = TimeSpan.FromSeconds(90);
            var header = new ProductHeaderValue("FilterLists.Agent");
            var userAgent = new ProductInfoHeaderValue(header);
            httpClient.DefaultRequestHeaders.UserAgent.Add(userAgent);
            _httpClient = httpClient;

            _logger = logger;
        }

        public async Task<Stream> GetAsStreamAsync(Uri url, CancellationToken cancellationToken)
        {
            using var response = await _httpClient.GetAsync(url, cancellationToken);
            if (response.IsSuccessStatusCode)
                return await response.Content.ReadAsStreamAsync();
            _logger.LogError($"Error downloading list from {url}. {response.StatusCode}");
            return Stream.Null;
        }
    }
}<commit_msg>caller of GetAsStreamAsync() should handle disposal of Stream, HttpResponseMessage doesn't necessarily need disposing itself<commit_after>﻿using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using FilterLists.Agent.Core.List;
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;

namespace FilterLists.Agent.Infrastructure
{
    [UsedImplicitly]
    public class ListRepository : IListRepository
    {
        private readonly HttpClient _httpClient;
        private readonly ILogger<ListRepository> _logger;

        public ListRepository(HttpClient httpClient, ILogger<ListRepository> logger)
        {
            httpClient.Timeout = TimeSpan.FromSeconds(90);
            var header = new ProductHeaderValue("FilterLists.Agent");
            var userAgent = new ProductInfoHeaderValue(header);
            httpClient.DefaultRequestHeaders.UserAgent.Add(userAgent);
            _httpClient = httpClient;

            _logger = logger;
        }

        [SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope")]
        public async Task<Stream> GetAsStreamAsync(Uri url, CancellationToken cancellationToken)
        {
            var response = await _httpClient.GetAsync(url, cancellationToken);
            if (response.IsSuccessStatusCode)
                return await response.Content.ReadAsStreamAsync();
            _logger.LogError($"Error downloading list from {url}. {response.StatusCode}");
            return Stream.Null;
        }
    }
}
{'fraction_non_alphanumeric': 0.07997334221926025, 'fraction_numerical': 0.0026657780739753416, 'mean_word_length': 3.1927374301675977, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4149461', 'n_tokens_mistral': 759, 'n_tokens_neox': 752, 'n_words': 174}