Skip to content

Commit ff3ca2a

Browse files
authored
[prerelease] Do not create a proxy agent if proxy url is empty string. (#8581)
2 parents ad7c008 + 14a0469 commit ff3ca2a

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# 2.90.x
77
* Register the CSharp context provider with Copilot Chat as well. (PR: [#8565](https://github.com/dotnet/vscode-csharp/pull/8565))
88
* Improve the limited activation experience (PR: [#8564](https://github.com/dotnet/vscode-csharp/pull/8564))
9+
* Do not create a proxy agent if proxy url is empty string. (PR: [#8564](https://github.com/dotnet/vscode-csharp/pull/8581))
910
* Bump Roslyn to 5.0.0-2.25428.10 (PR: [#8576](https://github.com/dotnet/vscode-csharp/pull/8576))
1011
* Fix issue reporting workspace diagnostics in Razor files (PR: [#80071](https://github.com/dotnet/roslyn/pull/80071))
1112
* Cache project analyzers (PR: [#80050](https://github.com/dotnet/roslyn/pull/80050))

src/packageManager/proxy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function getSystemProxyURL(requestURL: Url): string | undefined {
2121
export function getProxyAgent(requestURL: Url, proxy: string, strictSSL: boolean): Agent | undefined {
2222
const proxyURL = proxy.length > 0 ? proxy : getSystemProxyURL(requestURL);
2323

24-
if (proxyURL === undefined) {
24+
if (proxyURL === undefined || proxyURL.length === 0) {
2525
return undefined;
2626
}
2727

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { describe, test, expect, beforeAll, afterAll, beforeEach } from '@jest/globals';
7+
import { getProxyAgent } from '../../../../src/packageManager/proxy';
8+
import url from 'url';
9+
10+
describe(`${getProxyAgent.name}`, () => {
11+
let originalHttpProxy: string | undefined;
12+
let originalHttpsProxy: string | undefined;
13+
14+
const requestUrl = url.parse('https://github.com');
15+
16+
beforeAll(() => {
17+
originalHttpProxy = process.env.HTTP_PROXY;
18+
originalHttpsProxy = process.env.HTTPS_PROXY;
19+
});
20+
21+
afterAll(() => {
22+
if (originalHttpProxy !== undefined) {
23+
process.env.HTTP_PROXY = originalHttpProxy;
24+
} else {
25+
delete process.env.HTTP_PROXY;
26+
}
27+
28+
if (originalHttpsProxy !== undefined) {
29+
process.env.HTTPS_PROXY = originalHttpsProxy;
30+
} else {
31+
delete process.env.HTTPS_PROXY;
32+
}
33+
});
34+
35+
beforeEach(() => {
36+
delete process.env.HTTP_PROXY;
37+
delete process.env.HTTPS_PROXY;
38+
});
39+
40+
test('Returns `undefined` for empty proxy url and `undefined` HTTP_PROXY env', async () => {
41+
const result = getProxyAgent(requestUrl, /* proxy */ '', /* strictSSL */ false);
42+
expect(result).toBe(undefined);
43+
});
44+
45+
test('Returns `undefined` for empty proxy url and empty HTTP_PROXY env', async () => {
46+
process.env.HTTP_PROXY = '';
47+
process.env.HTTPS_PROXY = '';
48+
49+
const result = getProxyAgent(requestUrl, /* proxy */ '', /* strictSSL */ false);
50+
expect(result).toBe(undefined);
51+
});
52+
});

0 commit comments

Comments
 (0)