From 8cc941075a3e2182dda0ddc11714f967701e363f Mon Sep 17 00:00:00 2001 From: Henrik Cooke Date: Sat, 11 Apr 2020 16:17:48 +0200 Subject: [PATCH] Added timeout with default value of 30s (#132) * Added timeout with default value of 30s * Migrate from Request * Fixed incorrect default timeout Co-Authored-By: David Patrick * Forward timeout option into axios request options #132 Co-authored-by: davidpatrick Co-authored-by: David Patrick --- README.md | 1 + index.d.ts | 1 + src/JwksClient.js | 4 +++- src/wrappers/request.js | 3 ++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f00df66..ffcfca2 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ const client = jwksClient({ jwksUri: 'https://sandrino.auth0.com/.well-known/jwks.json', requestHeaders: {}, // Optional requestAgentOptions: {}, // Optional + timeout: ms('30s'), // Defaults to 30s proxy: '[protocol]://[username]:[pass]@[address]:[port]', // Optional }); diff --git a/index.d.ts b/index.d.ts index e617af2..e33cb10 100644 --- a/index.d.ts +++ b/index.d.ts @@ -25,6 +25,7 @@ declare namespace JwksRsa { proxy?: string; strictSsl?: boolean; requestHeaders?: Headers; + timeout?: number; } interface CertSigningKey { diff --git a/src/JwksClient.js b/src/JwksClient.js index 065ad7c..bfeb5c2 100644 --- a/src/JwksClient.js +++ b/src/JwksClient.js @@ -17,6 +17,7 @@ export class JwksClient { this.options = { rateLimit: false, cache: true, + timeout: 30000, ...options }; this.logger = debug('jwks'); @@ -37,7 +38,8 @@ export class JwksClient { strictSSL: this.options.strictSsl, headers: this.options.requestHeaders, agentOptions: this.options.requestAgentOptions, - proxy: this.options.proxy + proxy: this.options.proxy, + timeout: this.options.timeout }, (err, res) => { if (err) { const errorResponse = err.response; diff --git a/src/wrappers/request.js b/src/wrappers/request.js index d13b1e4..8964a23 100644 --- a/src/wrappers/request.js +++ b/src/wrappers/request.js @@ -6,7 +6,8 @@ import { request } from 'axios'; export default function(options, cb) { const requestOptions = { baseURL: options.uri, - headers: options.headers + headers: options.headers, + timeout: options.timeout }; if (options.proxy) {