<commit_before>import axios, { AxiosInstance, AxiosPromise, AxiosRequestConfig } from 'axios';
import qs from 'qs/lib';
import { PluginObject } from 'vue';

import * as strUtils from '../str/str';
import { RequestConfig, RestAdapter } from './rest';

const AUTHORIZATION_HEADER: string = 'Authorization';

export interface HttpPluginOptions {
    protectedUrls: string[];
    authorizationFn: () => string;
}

export class HttpService implements RestAdapter {
    public instance: AxiosInstance;

    constructor(private options?: HttpPluginOptions) {
        this.instance = axios.create({
            timeout: 30000 // TODO configure from plugin options
        });

        if (this.options) {
            let opt: HttpPluginOptions = this.options;
            this.instance.interceptors.request.use(config => {
                opt.protectedUrls.every(url => {
                    if (strUtils.startsWith(config.url, url)) {
                        let token: string = opt.authorizationFn();
                        config.headers = Object.assign({
                            [AUTHORIZATION_HEADER]: token
                        });
                        return false;
                    }
                    return true;
                });<commit_msg>MODUL-162 enlever le timeout par défaut pour la connection http (#252)<commit_after>import axios, { AxiosInstance, AxiosPromise, AxiosRequestConfig } from 'axios';
import qs from 'qs/lib';
import { PluginObject } from 'vue';

import * as strUtils from '../str/str';
import { RequestConfig, RestAdapter } from './rest';

const AUTHORIZATION_HEADER: string = 'Authorization';

export interface HttpPluginOptions {
    protectedUrls: string[];
    authorizationFn: () => string;
    timeout?: number;
}

export const NO_TIMEOUT: number = 0;

export class HttpService implements RestAdapter {
    public instance: AxiosInstance;

    constructor(private options?: HttpPluginOptions) {
        this.instance = axios.create();

        if (this.options) {
            if (!this.options.timeout) {
                this.instance.defaults.timeout = 30000;
            } else if (this.options.timeout === NO_TIMEOUT) {
                this.instance.defaults.timeout = undefined;
            } else {
                this.instance.defaults.timeout = this.options.timeout;
            }
            let opt: HttpPluginOptions = this.options;
            this.instance.interceptors.request.use(config => {
                opt.protectedUrls.every(url => {
                    if (strUtils.startsWith(config.url, url)) {
                        let token: string = opt.authorizationFn();
                        config.headers = Object.assign({
                            [AUTHORIZATION_HEADER]: token
                        });
                        return false;
                    }
                    return true;
                });
{'fraction_non_alphanumeric': 0.10034602076124567, 'fraction_numerical': 0.0058823529411764705, 'mean_word_length': 1.932048681541582, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6054409', 'n_tokens_mistral': 740, 'n_tokens_neox': 709, 'n_words': 181}