Skip to content

Commit 6961284

Browse files
committed
Fix validation to accept false as agent value
Fixes #2360
1 parent d1d4ed2 commit 6961284

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

source/core/options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ export default class Options {
11881188
}
11891189

11901190
// @ts-expect-error - No idea why `value[key]` doesn't work here.
1191-
assert.any([is.object, is.undefined], value[key]);
1191+
assert.any([is.object, is.undefined, (v: unknown) => v === false], value[key]);
11921192
}
11931193

11941194
if (this._merging) {

test/agent.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,48 @@ test('accept undefined agent', withServer, async (t, server, got) => {
219219
agent: undefinedAgent,
220220
})).body);
221221
});
222+
223+
test('accept false as agent value', withServer, async (t, server, got) => {
224+
server.get('/', (_request, response) => {
225+
response.end('ok');
226+
});
227+
228+
// Should not throw error when setting agent types to false
229+
t.notThrows(() => got.extend({
230+
agent: {
231+
http: false,
232+
https: false,
233+
http2: false,
234+
},
235+
}));
236+
237+
// Should successfully make request with false agent values
238+
const response = await got({
239+
agent: {
240+
http: false,
241+
},
242+
});
243+
244+
t.is(response.body, 'ok');
245+
});
246+
247+
test('accept mixed agent values with false', withServer, async (t, server, got) => {
248+
server.get('/', (_request, response) => {
249+
response.end('ok');
250+
});
251+
252+
const {agent: httpAgent} = createAgentSpy(HttpAgent);
253+
254+
// Should accept a mix of agent instance and false values
255+
const response = await got({
256+
agent: {
257+
http: httpAgent,
258+
https: false,
259+
http2: false,
260+
},
261+
});
262+
263+
t.is(response.body, 'ok');
264+
265+
httpAgent.destroy();
266+
});

0 commit comments

Comments
 (0)