<commit_before>goog.provide('api.AbstractApi');


/**
 * @constructor
 */
api.AbstractApi = function() {

};


/**
 * @param {string} url
 * @return {Promise}
 */
api.AbstractApi.prototype.request = function(url) {
	var xhr = new XMLHttpRequest();
	url = this._url + url;

	return new Promise(function(resolve, reject) {
		xhr.onreadystatechange = function() {
			if (xhr.readyState == 4) { // Request completed
				if (xhr.status == 200) {
					try {
						resolve(JSON.parse(xhr.responseText));
					} catch (e) {
						var err1 = new Error(e.message + '\n' + xhr.responseText.length + '\n' + url);
						reject(err1);
					}
				} else {
					var response;
					try {
						response = JSON.parse(xhr.responseText);
						if (response['error']) {
							reject(new Error(response['error'] + ': ' + xhr.status));
						} else {
							reject(new Error('Ошибка сети [1]: ' + xhr.status));
						}
					} catch (e) {
						reject(e);
					}
				}
			}
		};
		//xhr.open('GET', chrome.extension.getURL(url), true);
		xhr.open('GET', url, true);
		xhr.setRequestHeader("Authorization", "Basic a2ljdW1raWN1bToxMXpobG01");
		xhr.send();
	});
};<commit_msg>update abstract-api for set headers<commit_after>goog.provide('api.AbstractApi');


/**
 * @constructor
 */
api.AbstractApi = function() {

};


/**
 * @param {string} url
 * @param {Object.<string, string>=} opt_headers
 * @return {Promise}
 */
api.AbstractApi.prototype.request = function(url, opt_headers) {
	var xhr = new XMLHttpRequest();
	url = this._url + url;

	return new Promise(function(resolve, reject) {
		xhr.onreadystatechange = this._onReadyStateChange.bind(this, xhr, resolve, reject);
		xhr.open('GET', url, true);
		if (opt_headers) {
			this._setHeaders(xhr, opt_headers);
		}
		xhr.send();
	}.bind(this));
};


/**
 * @param {XMLHttpRequest} xhr
 * @param {Object.<string, string>} headers
 * @protected
 */
api.AbstractApi.prototype._setHeaders = function(xhr, headers) {
	for (var prop in headers) if (headers.hasOwnProperty(prop)) {
		xhr.setRequestHeader(prop, headers[prop]);
	}
};


api.AbstractApi.prototype._onReadyStateChange = function(xhr, resolve, reject) {
	if (xhr.readyState == 4) { // Request completed
		if (xhr.status == 200) {
			try {
				resolve(JSON.parse(xhr.responseText));
			} catch (e) {
				var err1 = new Error(e.message + '\n' + xhr.responseText.length + '\n' + url);
				reject(err1);
			}
		} else {
			var response;
			try {
				response = JSON.parse(xhr.responseText);
				if (response['error']) {
					reject(new Error(response['error'] + ': ' + xhr.status));
				} else {
					reject(new Error('Ошибка сети [1]: ' + xhr.status));
				}
			} catch (e) {
				reject(e);
			}
		}
	}
};
{'fraction_non_alphanumeric': 0.17657992565055763, 'fraction_numerical': 0.007063197026022305, 'mean_word_length': 3.2046875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7425782', 'n_tokens_mistral': 1127, 'n_tokens_neox': 948, 'n_words': 185}