export function toRequestOptions()

in lib/shared.ts [20:49]


export function toRequestOptions(url, token, headers) {
    headers = headers || {
        'user-agent': 'nodejs'
    };

    if (token) {
        headers['Authorization'] = 'token ' + token;
    }

    let parsedUrl = new URL(url);

    var options: any = {
        url: url,
        headers: headers
    };

    // We need to test the absence of true here because there is an npm bug that will not set boolean
    // env variables if they are set to false.
    if (process.env.npm_config_strict_ssl !== 'true') {
        options.strictSSL = false;
    }

    if (process.env.npm_config_proxy && parsedUrl.protocol === 'http:') {
        options.proxy = process.env.npm_config_proxy;
    } else if (process.env.npm_config_https_proxy && parsedUrl.protocol === 'https:') {
        options.proxy = process.env.npm_config_https_proxy;
    }

    return options;
}