Skip to content

Commit

Permalink
rename timeout option before passign to http.request
Browse files Browse the repository at this point in the history
  • Loading branch information
floatdrop committed Dec 29, 2016
1 parent e367ee4 commit 52ddf95
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -289,6 +289,11 @@ function normalizeArguments(url, opts) {
opts.followRedirect = true;
}

if (opts.timeout) {
opts.gotTimeout = opts.timeout;
delete opts.timeout;
}

return opts;
}

Expand Down
12 changes: 12 additions & 0 deletions test/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 52ddf95

Please sign in to comment.