Skip to content

Commit

Permalink
feat(request): add noProxy setting for configuration (yarnpkg#5048)
Browse files Browse the repository at this point in the history
  • Loading branch information
glausmichael committed Apr 30, 2018
1 parent 202f1f5 commit 2612130
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
29 changes: 17 additions & 12 deletions __tests__/util/request-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ const setupServer = async () => {

return {
caFilePath: path.join(__dirname, '..', 'fixtures', 'certificates', 'cacerts.pem'),
httpPort: httpPort,
httpPort,
httpUrl: `http://localhost:${httpPort}/?nocache`,
httpsPort: httpsPort,
httpsPort,
httpsUrl: `https://localhost:${httpsPort}/?nocache`,
close: () => {
httpsServer.close();
httpServer.close();
}
}
},
};
};

const setProxyEnvVars = () => {
Expand All @@ -170,7 +170,7 @@ test('RequestManager.request with env vars proxy options and only no-proxy optio
setProxyEnvVars();

const configWithoutProxyExclusion = await Config.create({
cafile: server.caFilePath
cafile: server.caFilePath,
});

let error;
Expand All @@ -179,7 +179,7 @@ test('RequestManager.request with env vars proxy options and only no-proxy optio
url: server.httpsUrl,
headers: {Connection: 'close'},
});
} catch(e) {
} catch (e) {
error = e;
}
expect(error).toBeTruthy();
Expand All @@ -190,7 +190,7 @@ test('RequestManager.request with env vars proxy options and only no-proxy optio
url: server.httpUrl,
headers: {Connection: 'close'},
});
} catch(e) {
} catch (e) {
error = e;
}
expect(error).toBeTruthy();
Expand All @@ -212,6 +212,7 @@ test('RequestManager.request with env vars proxy options and only no-proxy optio
});
expect(successfulRequestBody).toBe('ok');
} finally {
deleteProxyEnvVars();
server.close();
}
});
Expand All @@ -232,7 +233,7 @@ const testProxyOptionsInConfigFile = async () => {
url: server.httpsUrl,
headers: {Connection: 'close'},
});
} catch(e) {
} catch (e) {
error = e;
}
expect(error).toBeTruthy();
Expand All @@ -243,7 +244,7 @@ const testProxyOptionsInConfigFile = async () => {
url: server.httpUrl,
headers: {Connection: 'close'},
});
} catch(e) {
} catch (e) {
error = e;
}
expect(error).toBeTruthy();
Expand Down Expand Up @@ -273,12 +274,16 @@ const testProxyOptionsInConfigFile = async () => {

test('RequestManager.request with proxy and no-proxy options only in config without env vars', async () => {
deleteProxyEnvVars();
testProxyOptionsInConfigFile();
await testProxyOptionsInConfigFile();
});

test('RequestManager.request with both proxy options in env vars and config and no-proxy options in config', async () => {
setProxyEnvVars();
testProxyOptionsInConfigFile();
try{
setProxyEnvVars();
await testProxyOptionsInConfigFile();
} finally {
deleteProxyEnvVars();
}
});

test('RequestManager.execute timeout error with maxRetryAttempts=1', async () => {
Expand Down
9 changes: 7 additions & 2 deletions src/util/proxy-exclusion.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* @flow */

import {URL} from 'url';
import * as urlMod from 'url';

type Zone = {
hostname: string,
Expand Down Expand Up @@ -37,7 +37,12 @@ export default function isExcludedFromProxy(url: string, noProxy: string): boole
return true;
}

const uri = new URL(url);
let uri;
if (urlMod.URL) {
uri = new urlMod.URL(url);
} else {
uri = urlMod.parse(url);
}

const port = uri.port || (uri.protocol === 'https:' ? '443' : '80');
const hostname = formatHostname(uri.hostname);
Expand Down

0 comments on commit 2612130

Please sign in to comment.