<commit_before>﻿#if !DOTNET5_4
using Discord.API;
using RestSharp;
using System;
using System.IO;
using System.Net;
using System.Threading;
using System.Threading.Tasks;

namespace Discord.Net.Rest
{
    internal sealed class RestSharpEngine : IRestEngine
	{
		private readonly DiscordAPIClientConfig _config;
		private readonly RestSharp.RestClient _client;

        public RestSharpEngine(DiscordAPIClientConfig config)
		{
			_config = config;
			_client = new RestSharp.RestClient(Endpoints.BaseApi)
			{
				PreAuthenticate = false,
				ReadWriteTimeout = _config.APITimeout,
				UserAgent = DiscordAPIClientConfig.UserAgent
			};
			if (_config.ProxyUrl != null)
				_client.Proxy = new WebProxy(_config.ProxyUrl, true, new string[0], _config.ProxyCredentials);
			else
				_client.Proxy = null;
            _client.RemoveDefaultParameter("Accept");
            _client.AddDefaultHeader("accept", "*/*");
			_client.AddDefaultHeader("accept-encoding", "gzip,deflate");
        }

		public void SetToken(string token)
		{
			_client.RemoveDefaultParameter("authorization");
			if (token != null)
				_client.AddDefaultHeader("authorization", token);
		}

		public Task<string> Send(string method, string path, string json, CancellationToken cancelToken)
		{
			var request = new RestRequest(path, GetMethod(method));
			request.AddParameter("application/json", json, ParameterType.RequestBody);
			return Send(request, cancelToken);
		}
		public Task<string> SendFile(string method, string path, string filename, Stream stream, CancellationToken cancelToken)
		{
			var request = new RestRequest(path, Method.POST);
            request.AddFile("file", x => stream.CopyTo(x), filename);
            return Send(request, cancelToken);
		}
		private async Task<string> Send(RestRequest request, CancellationToken cancelToken)
		{
			int retryCount = 0;
			while (true)
			{
				var response = await _client.ExecuteTaskAsync(request, cancelToken).ConfigureAwait(false);
				int statusCode = (int)response.StatusCode;<commit_msg>Fixed SendFile<commit_after>﻿#if !DOTNET5_4
using Discord.API;
using RestSharp;
using System;
using System.IO;
using System.Net;
using System.Threading;
using System.Threading.Tasks;

namespace Discord.Net.Rest
{
    internal sealed class RestSharpEngine : IRestEngine
	{
		private readonly DiscordAPIClientConfig _config;
		private readonly RestSharp.RestClient _client;

        public RestSharpEngine(DiscordAPIClientConfig config)
		{
			_config = config;
			_client = new RestSharp.RestClient(Endpoints.BaseApi)
			{
				PreAuthenticate = false,
				ReadWriteTimeout = _config.APITimeout,
				UserAgent = DiscordAPIClientConfig.UserAgent
			};
			if (_config.ProxyUrl != null)
				_client.Proxy = new WebProxy(_config.ProxyUrl, true, new string[0], _config.ProxyCredentials);
			else
				_client.Proxy = null;
            _client.RemoveDefaultParameter("Accept");
            _client.AddDefaultHeader("accept", "*/*");
			_client.AddDefaultHeader("accept-encoding", "gzip,deflate");
        }

		public void SetToken(string token)
		{
			_client.RemoveDefaultParameter("authorization");
			if (token != null)
				_client.AddDefaultHeader("authorization", token);
		}

		public Task<string> Send(string method, string path, string json, CancellationToken cancelToken)
		{
			var request = new RestRequest(path, GetMethod(method));
			request.AddParameter("application/json", json, ParameterType.RequestBody);
			return Send(request, cancelToken);
		}
		public Task<string> SendFile(string method, string path, string filename, Stream stream, CancellationToken cancelToken)
		{
			var request = new RestRequest(path, Method.POST);
			request.AddHeader("content-length", (stream.Length - stream.Position).ToString());

			byte[] bytes = new byte[stream.Length - stream.Position];
			stream.Read(bytes, 0, bytes.Length);
			request.AddFileBytes("file", bytes, filename);
			//request.AddFile("file", x => stream.CopyTo(x), filename); (Broken in latest ver)

			return Send(request, cancelToken);
		}
		private async Task<string> Send(RestRequest request, CancellationToken cancelToken)
		{
			int retryCount = 0;
			while (true)
			{
				var response = await _client.ExecuteTaskAsync(request, cancelToken).ConfigureAwait(false);
				int statusCode = (int)response.StatusCode;
{'fraction_non_alphanumeric': 0.1059233449477352, 'fraction_numerical': 0.0020905923344947735, 'mean_word_length': 4.402760351317441, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '1680065', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1256, 'n_words': 292}