Skip to content

Commit

Permalink
fix: looking up timeout on agent with no options (#2299)
Browse files Browse the repository at this point in the history
  • Loading branch information
mastermatt committed Feb 4, 2022
1 parent 616d903 commit 1b2933d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/intercepted_request_router.js
Expand Up @@ -54,7 +54,9 @@ class InterceptedRequestRouter {
// any timeout in the request options override any timeout in the agent options.
// per https://github.com/nodejs/node/pull/21204
const timeout =
options.timeout || (options.agent && options.agent.options.timeout)
options.timeout ||
(options.agent && options.agent.options && options.agent.options.timeout)

if (timeout) {
this.socket.setTimeout(timeout)
}
Expand Down
14 changes: 14 additions & 0 deletions tests/test_request_overrider.js
Expand Up @@ -826,4 +826,18 @@ describe('Request Overrider', () => {

expect(response).to.equal('BUFFER_SENT')
})

// https://github.com/nock/nock/issues/2298
it('should handle non-default agents', async () => {
nock('https://example.test').get('/').reply(200, 'OK')

const agent = {
foo: 'bar',
}

const { statusCode } = await got('https://example.test', {
agent: { https: agent },
})
expect(statusCode).to.equal(200)
})
})

0 comments on commit 1b2933d

Please sign in to comment.