Browse Source

rename timeout option before passign to http.request

extract-response
Vsevolod Strukchinsky 8 years ago
parent
commit
52ddf95efc
  1. 9
      index.js
  2. 12
      test/http.js

9
index.js

@ -73,8 +73,8 @@ function requestAsEventEmitter(opts) {
ee.emit('error', new got.RequestError(err, opts));
});
if (opts.timeout) {
timedOut(req, opts.timeout);
if (opts.gotTimeout) {
timedOut(req, opts.gotTimeout);
}
setImmediate(() => {
@ -289,6 +289,11 @@ function normalizeArguments(url, opts) {
opts.followRedirect = true;
}
if (opts.timeout) {
opts.gotTimeout = opts.timeout;
delete opts.timeout;
}
return opts;
}

12
test/http.js

@ -73,6 +73,18 @@ test('timeout option', async t => {
}
});
test('timeout option as object', async t => {
try {
await got(`${s.url}/404`, {
timeout: {connect: 1},
retries: 0
});
t.fail('Exception was not thrown');
} catch (err) {
t.is(err.code, 'ETIMEDOUT');
}
});
test('query option', async t => {
t.is((await got(s.url, {query: {recent: true}})).body, 'recent');
t.is((await got(s.url, {query: 'recent=true'})).body, 'recent');

Loading…
Cancel
Save