This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Install is not refactored, leave shared, request and url-parse
- Loading branch information
Showing
4 changed files
with
434 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/*--------------------------------------------------------- | ||
* Copyright (C) Microsoft Corporation. All rights reserved. | ||
*--------------------------------------------------------*/ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var request = require('request'); | ||
var URL = require('url-parse'); | ||
function getContents(url, token, headers, callback) { | ||
request.get(toRequestOptions(url, token, headers), function (error, response, body) { | ||
if (!error && response && response.statusCode >= 400) { | ||
error = new Error('Request returned status code: ' + response.statusCode + '\nDetails: ' + response.body); | ||
} | ||
callback(error, body); | ||
}); | ||
} | ||
exports.getContents = getContents; | ||
function toRequestOptions(url, token, headers) { | ||
headers = headers || { | ||
'user-agent': 'nodejs' | ||
}; | ||
if (token) { | ||
headers['Authorization'] = 'token ' + token; | ||
} | ||
var parsedUrl = new URL(url); | ||
var options = { | ||
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; | ||
} | ||
exports.toRequestOptions = toRequestOptions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/*--------------------------------------------------------- | ||
* Copyright (C) Microsoft Corporation. All rights reserved. | ||
*--------------------------------------------------------*/ | ||
|
||
'use strict'; | ||
|
||
var request = require('request'); | ||
var URL = require('url-parse'); | ||
|
||
export function getContents(url, token, headers, callback) { | ||
request.get(toRequestOptions(url, token, headers), function (error, response, body) { | ||
if (!error && response && response.statusCode >= 400) { | ||
error = new Error('Request returned status code: ' + response.statusCode + '\nDetails: ' + response.body); | ||
} | ||
|
||
callback(error, body); | ||
}); | ||
} | ||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.