Skip to content

Commit

Permalink
fix: move to getAgent instead of just using getUrlProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
NlightNFotis committed Dec 2, 2024
1 parent 876084f commit 8d1e908
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
14 changes: 5 additions & 9 deletions lib/tools-download.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/tools-download.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 5 additions & 10 deletions src/tools-download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from "path";
import { performance } from "perf_hooks";

import * as core from "@actions/core";
import { getProxyUrl } from "@actions/http-client/lib/proxy";
import { HttpClient } from "@actions/http-client";
import * as toolcache from "@actions/tool-cache";
import { https } from "follow-redirects";
import { v4 as uuidV4 } from "uuid";
Expand Down Expand Up @@ -186,8 +186,8 @@ async function downloadAndExtractZstdWithStreaming(
tarVersion: tar.TarVersion,
logger: Logger,
): Promise<string> {
// Attempt to detect a proxy URL that should be used for the download.
const downloadUrl = adjustUrlByProxy(codeqlURL) || codeqlURL;
// Get Agent to use (respects proxy settings).
const agent = new HttpClient().getAgent(codeqlURL);

headers = Object.assign(
{ "User-Agent": "CodeQL Action" },
Expand All @@ -196,10 +196,11 @@ async function downloadAndExtractZstdWithStreaming(
);
const response = await new Promise<IncomingMessage>((resolve) =>
https.get(
downloadUrl,
codeqlURL,
{
headers,
highWaterMark: STREAMING_HIGH_WATERMARK_BYTES,
agent,
} as unknown as RequestOptions,
(r) => resolve(r),
),
Expand All @@ -221,9 +222,3 @@ function sanitizeUrlForStatusReport(url: string): string {
? url
: "sanitized-value";
}

// Auxiliary function to retrieve the proxy URL to use for a given URL, if proxy settings are configured.
function adjustUrlByProxy(url: string): string | undefined {
const proxyUrl = getProxyUrl(new URL(url));
return proxyUrl ? proxyUrl.toString() : undefined;
}

0 comments on commit 8d1e908

Please sign in to comment.