Skip to content

Commit 409894b

Browse files
committed
Add support for timeout and cookies through settings and headers
1 parent 3b0bd7e commit 409894b

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

lib/request.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ function prepare(input){
103103
let auth = input.headers.auth || {};
104104
let settings = {
105105
autoHeaders: !input.headers['no-auto'] || false,
106-
cookies: input.headers.cookies || false,
107-
timeout: input.timeout || false,
106+
cookies: input.cookies || input.headers.cookies || false,
107+
timeout: input.timeout || input.headers.timeout || false,
108108

109109
auth: auth.username || url.username ? {
110110
username: auth.username || url.username,

test/spec.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,7 @@ describe('Assertions', function(){
237237

238238
describe('Timeout', function(){
239239

240-
it('Should reject when response time exceeds setup timeout', function(){
241-
assert.rejects(() => muhb.request({
242-
method: 'GET',
243-
url: HTTPBIN_URL + '/delay/10000',
244-
timeout: 1000
245-
}), /timeout/g);
246-
});
240+
247241

248242
});
249243

@@ -379,4 +373,18 @@ describe('Other Features', function(){
379373
assert.strictEqual(body.length, 16);
380374
});
381375

376+
it('Should reject when response time exceeds setup timeout', async function(){
377+
await assert.rejects(() => muhb.request({
378+
method: 'GET',
379+
url: HTTPBIN_URL + '/delay/10000',
380+
timeout: 500
381+
}), /timeout/g);
382+
383+
await assert.rejects(() => muhb.request({
384+
method: 'GET',
385+
url: HTTPBIN_URL + '/delay/10000',
386+
headers: { timeout: 500 }
387+
}), /timeout/g);
388+
});
389+
382390
});

0 commit comments

Comments
 (0)