@@ -38,6 +38,7 @@ import lim = require("./interfaces/LocationsInterfaces");
3838import crypto = require( 'crypto' ) ;
3939import fs = require( 'fs' ) ;
4040import os = require( 'os' ) ;
41+ import url = require( 'url' ) ;
4142
4243/**
4344 * Methods to return handler objects (see handlers folder)
@@ -97,17 +98,19 @@ export class WebApi {
9798 this . authHandler = authHandler ;
9899 this . options = options || { } ;
99100
100- // try get proxy setting from environment variable set by VSTS-Task-Lib if there is no proxy setting in the options
101- if ( ! this . options . proxy || ! this . options . proxy . proxyUrl ) {
102- if ( global [ '_vsts_task_lib_proxy' ] ) {
103- let proxyFromEnv : VsoBaseInterfaces . IProxyConfiguration = {
104- proxyUrl : global [ '_vsts_task_lib_proxy_url' ] ,
105- proxyUsername : global [ '_vsts_task_lib_proxy_username' ] ,
106- proxyPassword : this . _readTaskLibSecrets ( global [ '_vsts_task_lib_proxy_password' ] ) ,
107- proxyBypassHosts : JSON . parse ( global [ '_vsts_task_lib_proxy_bypass' ] || "[]" ) ,
108- } ;
109-
110- this . options . proxy = proxyFromEnv ;
101+ if ( ! this . isNoProxyHost ( this . serverUrl ) ) {
102+ // try to get proxy setting from environment variable set by VSTS-Task-Lib if there is no proxy setting in the options
103+ if ( ! this . options . proxy || ! this . options . proxy . proxyUrl ) {
104+ if ( global [ '_vsts_task_lib_proxy' ] ) {
105+ let proxyFromEnv : VsoBaseInterfaces . IProxyConfiguration = {
106+ proxyUrl : global [ '_vsts_task_lib_proxy_url' ] ,
107+ proxyUsername : global [ '_vsts_task_lib_proxy_username' ] ,
108+ proxyPassword : this . _readTaskLibSecrets ( global [ '_vsts_task_lib_proxy_password' ] ) ,
109+ proxyBypassHosts : JSON . parse ( global [ '_vsts_task_lib_proxy_bypass' ] || "[]" ) ,
110+ } ;
111+
112+ this . options . proxy = proxyFromEnv ;
113+ }
111114 }
112115 }
113116
@@ -136,7 +139,7 @@ export class WebApi {
136139 const osName : string = os . platform ( ) ;
137140 const osVersion : string = os . release ( ) ;
138141
139- if ( requestSettings ) {
142+ if ( requestSettings ) {
140143 userAgent = `${ requestSettings . productName } /${ requestSettings . productVersion } (${ nodeApiName } ${ nodeApiVersion } ; ${ osName } ${ osVersion } )` ;
141144 }
142145 else {
@@ -331,6 +334,19 @@ export class WebApi {
331334 return new workitemtrackingprocessdefinitionm . WorkItemTrackingProcessDefinitionsApi ( serverUrl , handlers , this . options ) ;
332335 }
333336
337+ /**
338+ * Determines if the domain is exluded for proxy via the no_proxy env var
339+ * @param url: the server url
340+ */
341+ public isNoProxyHost = function ( _url : string ) {
342+ const noProxyDomains = ( process . env . no_proxy || '' )
343+ . split ( ',' )
344+ . map ( v => v . toLowerCase ( ) ) ;
345+ const serverUrl = url . parse ( _url ) . host . toLowerCase ( ) ;
346+ // return true if the no_proxy includes the host
347+ return noProxyDomains . indexOf ( serverUrl ) !== - 1 ;
348+ }
349+
334350 private async _getResourceAreaUrl ( serverUrl : string , resourceId : string ) : Promise < string > {
335351 if ( ! resourceId ) {
336352 return serverUrl ;
0 commit comments