<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace SyncTrayzor.SyncThing
{
    public class AuthenticatedHttpClientHandler : WebRequestHandler
    {
        private readonly string apiKey;

        public AuthenticatedHttpClientHandler(string apiKey)
        {
            this.apiKey = apiKey;
            // We expect Syncthing to return invalid certs
            this.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
        }

        protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            request.Headers.Add("X-API-Key", this.apiKey);
            return base.SendAsync(request, cancellationToken);
        }
    }
}<commit_msg>Log raw HTTP data<commit_after>﻿using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace SyncTrayzor.SyncThing
{
    public class AuthenticatedHttpClientHandler : WebRequestHandler
    {
        private static readonly Logger logger = LogManager.GetCurrentClassLogger();
        private readonly string apiKey;

        public AuthenticatedHttpClientHandler(string apiKey)
        {
            this.apiKey = apiKey;
            // We expect Syncthing to return invalid certs
            this.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
        }

        protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            request.Headers.Add("X-API-Key", this.apiKey);
            if (logger.IsDebugEnabled)
            {
                var response = await base.SendAsync(request, cancellationToken);
                logger.Debug((await response.Content.ReadAsStringAsync()).Trim());
                return response;
            }
            else
            {
                return await base.SendAsync(request, cancellationToken);
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.07664724338861498, 'fraction_numerical': 0.0, 'mean_word_length': 2.6892561983471075, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1691186', 'n_tokens_mistral': 554, 'n_tokens_neox': 554, 'n_words': 133}