Skip to content

Add request options as optional param for downloadTool #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ declare let rest;

let pkg = require(path.join(__dirname, 'package.json'));
let userAgent = 'vsts-task-installer/' + pkg.version;
let requestOptions = {
const defaultRequestOptions = {
// ignoreSslError: true,
proxy: tl.getHttpProxyConfiguration(),
cert: tl.getHttpCertConfiguration(),
Expand Down Expand Up @@ -198,17 +198,20 @@ export function findLocalToolVersions(toolName: string, arch?: string) {
* @param fileName optional fileName. Should typically not use (will be a guid for reliability). Can pass fileName with an absolute path.
* @param handlers optional handlers array. Auth handlers to pass to the HttpClient for the tool download.
* @param additionalHeaders optional custom HTTP headers. This is passed to the REST client that downloads the tool.
* @param requestOptions optional request options. This is passed to the REST client that downloads the tool.
*/
export async function downloadTool(
url: string,
fileName?: string,
handlers?: ifm.IRequestHandler[],
additionalHeaders?: ifm.IHeaders
additionalHeaders?: ifm.IHeaders,
requestOptions?: ifm.IRequestOptions
): Promise<string> {
return new Promise<string>(async (resolve, reject) => {
try {
handlers = handlers || null;
let http: httpm.HttpClient = new httpm.HttpClient(userAgent, handlers, requestOptions);
requestOptions = { ...defaultRequestOptions, ...requestOptions || {} }
const http = new httpm.HttpClient(userAgent, handlers, requestOptions);
tl.debug(fileName);
fileName = fileName || uuidV4();

Expand Down Expand Up @@ -471,10 +474,10 @@ export async function extract7z(file: string, dest?: string, _7zPath?: string, o
}

_7z.arg('x') // eXtract files with full paths
.arg('-bb1') // -bb[0-3] : set output log level
.arg('-bd') // disable progress indicator
.arg('-sccUTF-8') // set charset for for console input/output
.arg(file);
.arg('-bb1') // -bb[0-3] : set output log level
.arg('-bd') // disable progress indicator
.arg('-sccUTF-8') // set charset for for console input/output
.arg(file);
await _7z.exec();
}
else {
Expand Down Expand Up @@ -591,7 +594,7 @@ function _createExtractFolder(dest?: string): string {
*/
export async function scrape(url: string, regex: RegExp, handlers?: ifm.IRequestHandler[]): Promise<string[]> {
handlers = handlers || null;
let http: httpm.HttpClient = new httpm.HttpClient(userAgent, handlers, requestOptions);
let http: httpm.HttpClient = new httpm.HttpClient(userAgent, handlers, defaultRequestOptions);
let output: string = await (await http.get(url)).readBody();

let matches = output.match(regex);
Expand Down