From 12ca5da55ecd7be4280a9847fd6df7bb144fba70 Mon Sep 17 00:00:00 2001 From: "Matt R. Wilson" Date: Fri, 4 Feb 2022 10:40:28 -0700 Subject: [PATCH 1/2] wip: failing case --- tests/test_request_overrider.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/test_request_overrider.js b/tests/test_request_overrider.js index 515011040..be973706b 100644 --- a/tests/test_request_overrider.js +++ b/tests/test_request_overrider.js @@ -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) + }) }) From 562256637eacba2a284fa55ac67c3da844795099 Mon Sep 17 00:00:00 2001 From: "Matt R. Wilson" Date: Fri, 4 Feb 2022 10:43:09 -0700 Subject: [PATCH 2/2] fix(router): guard against agents without `options` fixes #2298 --- lib/intercepted_request_router.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/intercepted_request_router.js b/lib/intercepted_request_router.js index 54398f573..8c42d287e 100644 --- a/lib/intercepted_request_router.js +++ b/lib/intercepted_request_router.js @@ -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) }