diff --git a/src/agents.ts b/src/agents.ts index b6c432f..9e29659 100644 --- a/src/agents.ts +++ b/src/agents.ts @@ -34,10 +34,10 @@ export type HttpAnyAgent = HTTPAgent | HTTPSAgent; * @returns {HttpAnyAgent|undefined} */ export function getAgent( - uri: string, + uri: string | undefined, reqOpts: Options ): HttpAnyAgent | undefined { - const isHttp = uri.startsWith('http://'); + const isHttp = uri?.startsWith('http://'); const proxy = reqOpts.proxy || process.env.HTTP_PROXY || diff --git a/test/agents.ts b/test/agents.ts index 5b082aa..ee90a14 100644 --- a/test/agents.ts +++ b/test/agents.ts @@ -45,6 +45,11 @@ describe('agents', () => { assert.strictEqual(agent, undefined); }); + it('should return undefined if httpUri is undefined', () => { + const agent = getAgent(undefined, defaultOptions); + assert.strictEqual(agent, undefined); + }); + describe('proxy', () => { const envVars = [ 'http_proxy',