<commit_before>import { ConnectionBackend, Request, Connection } from '@angular/http';
import { Injectable } from '@angular/core';
import { NativeHttpBackend } from './native-http-backend';
import { checkAvailability } from '@ionic-native/core';

@Injectable()
export class NativeHttpFallback implements ConnectionBackend {

    protected nativeIsForced: boolean | null = null;
    protected nativeIsAvailable: boolean | null = null;

    constructor(
        private nativeHttpBackend: NativeHttpBackend,
        private fallback: ConnectionBackend
    ) {
    }

    createConnection(request: Request): Connection {
        /**
         * Native HTTP Cordova plugin doesn't like local requests
         */
        const isOutgoingRequest = /^(http|https):\/\//.test(request.url);

        if (isOutgoingRequest && this.isNativeHttpAvailable()) {
            return this.nativeHttpBackend.createConnection(request);
        } else {
            return this.fallback.createConnection(request);
        }
    }

    /**
     * Enable/disable forced native HTTP usage without preliminary check. Helpful for unit testing
     *
     * @param {boolean} isEnabled
     */
    forceNative(isEnabled: boolean) {
        this.nativeIsForced = isEnabled;
    }

    protected isNativeHttpAvailable() {
        if (this.nativeIsForced !== null) {
            return this.nativeIsForced;
        }

        if (this.nativeIsAvailable === null) {
            this.nativeIsAvailable = checkAvailability('cordovaHTTP2') === true;
        }

        return this.nativeIsAvailable;
    }
}<commit_msg>fix(NativeHttpFallback): Specify cordova-plugin-advanced-http ref<commit_after>import { ConnectionBackend, Request, Connection } from '@angular/http';
import { Injectable } from '@angular/core';
import { NativeHttpBackend } from './native-http-backend';
import { checkAvailability } from '@ionic-native/core';

@Injectable()
export class NativeHttpFallback implements ConnectionBackend {

    protected nativeIsForced: boolean | null = null;
    protected nativeIsAvailable: boolean | null = null;

    constructor(
        private nativeHttpBackend: NativeHttpBackend,
        private fallback: ConnectionBackend
    ) {
    }

    createConnection(request: Request): Connection {
        /**
         * Native HTTP Cordova plugin doesn't like local requests
         */
        const isOutgoingRequest = /^(http|https):\/\//.test(request.url);

        if (isOutgoingRequest && this.isNativeHttpAvailable()) {
            return this.nativeHttpBackend.createConnection(request);
        } else {
            return this.fallback.createConnection(request);
        }
    }

    /**
     * Enable/disable forced native HTTP usage without preliminary check. Helpful for unit testing
     *
     * @param {boolean} isEnabled
     */
    forceNative(isEnabled: boolean) {
        this.nativeIsForced = isEnabled;
    }

    protected isNativeHttpAvailable() {
        if (this.nativeIsForced !== null) {
            return this.nativeIsForced;
        }

        if (this.nativeIsAvailable === null) {
            this.nativeIsAvailable = checkAvailability('cordova.plugin.http') === true;
        }

        return this.nativeIsAvailable;
    }
}
{'fraction_non_alphanumeric': 0.1028182099721276, 'fraction_numerical': 0.0003096934035305048, 'mean_word_length': 2.786635404454865, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1655071', 'n_tokens_mistral': 843, 'n_tokens_neox': 828, 'n_words': 197}