<commit_before>﻿using System;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace MailRuCloudApi.Api.Requests
{
    public abstract class BaseRequest<T> where T : class
    {

        protected readonly CloudApi CloudApi;

        protected BaseRequest(CloudApi cloudApi)
        {
            CloudApi = cloudApi;
        }

        public virtual string RelationalUri { get; protected set; }

        public virtual HttpWebRequest CreateRequest(string baseDomain = null)
        {
            string domain = string.IsNullOrEmpty(baseDomain) ? ConstSettings.CloudDomain : baseDomain;
            var uriz = new Uri(new Uri(domain), RelationalUri);

            var request = (HttpWebRequest)WebRequest.Create(uriz);
            request.Proxy = CloudApi.Account.Proxy;
            request.CookieContainer = CloudApi.Account.Cookies;
            request.Method = "GET";
            request.ContentType = ConstSettings.DefaultRequestType;
            request.Accept = "application/json";
            request.UserAgent = ConstSettings.UserAgent;

            return request;
        }

        protected virtual byte[] CreateHttpContent()
        {
            return null;
        }


        public virtual async Task<T> MakeRequestAsync()
        {
            var httprequest = CreateRequest();

            var content = CreateHttpContent();
            if (content != null)
            {
                httprequest.Method = "POST";
                var stream = httprequest.GetRequestStream();
                stream.Write(content, 0, content.Length);
            }

            using (var response = (HttpWebResponse)await Task.Factory.FromAsync(httprequest.BeginGetResponse, asyncResult => httprequest.EndGetResponse(asyncResult), null))
            {

                if ((int)response.StatusCode >= 500)
                    throw new RequestException("Server fault"); // Let's throw exception. It's server fault<commit_msg>minor BaseRequest change<commit_after>﻿using System;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace MailRuCloudApi.Api.Requests
{
    public abstract class BaseRequest<T> where T : class
    {

        protected readonly CloudApi CloudApi;

        protected BaseRequest(CloudApi cloudApi)
        {
            CloudApi = cloudApi;
        }

        public virtual string RelationalUri { get; protected set; }

        public virtual HttpWebRequest CreateRequest(string baseDomain = null)
        {
            string domain = string.IsNullOrEmpty(baseDomain) ? ConstSettings.CloudDomain : baseDomain;
            var uriz = new Uri(new Uri(domain), RelationalUri);

            var request = (HttpWebRequest)WebRequest.Create(uriz);
            request.Proxy = CloudApi.Account.Proxy;
            request.CookieContainer = CloudApi.Account.Cookies;
            request.Method = "GET";
            request.ContentType = ConstSettings.DefaultRequestType;
            request.Accept = "application/json";
            request.UserAgent = ConstSettings.UserAgent;

            return request;
        }

        protected virtual byte[] CreateHttpContent()
        {
            return null;
        }


        public virtual async Task<T> MakeRequestAsync()
        {
            var httprequest = CreateRequest();

            var content = CreateHttpContent();
            if (content != null)
            {
                httprequest.Method = "POST";
                var stream = httprequest.GetRequestStream();
                stream.Write(content, 0, content.Length);
            }

            using (var response = (HttpWebResponse)await Task.Factory.FromAsync(httprequest.BeginGetResponse, asyncResult => httprequest.EndGetResponse(asyncResult), null))
            {

                if ((int)response.StatusCode >= 500)
                    throw new RequestException("Server fault") {StatusCode = response.StatusCode}; // Let's throw exception. It's server fault
{'fraction_non_alphanumeric': 0.08463796477495107, 'fraction_numerical': 0.0019569471624266144, 'mean_word_length': 2.2171518489378443, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4429077', 'n_tokens_mistral': 1014, 'n_tokens_neox': 972, 'n_words': 247}