Skip to content

Commit

Permalink
feat(timeout): plumb a timeout option for HTTP requests (#339)
Browse files Browse the repository at this point in the history
Fixes #328
  • Loading branch information
silasbw committed Oct 19, 2018
1 parent e8d914b commit 6a9f06d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
30 changes: 30 additions & 0 deletions examples/timeout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* eslint no-console:0 */
//
// Demonstrate how to set an HTTP request timeout.
//
const Client = require('../').Client;
const config = require('../').config;

async function main() {
try {
//
// Set a long timeout for HTTP requests of 30,000 milliseconds.
//
const timeout = 30000;
const client = new Client({
config: Object.assign(config.fromKubeconfig(), { timeout }),
version: '1.9'
});

//
// Get all the Namespaces.
//
const namespaces = await client.api.v1.namespaces.get();
console.log('Namespaces: ', namespaces);

} catch (err) {
console.error('Error: ', err);
}
}

main();
11 changes: 7 additions & 4 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,16 @@ class Request {
this.requestOptions.ca = options.ca;
this.requestOptions.cert = options.cert;
this.requestOptions.key = options.key;
this.authProvider = {
type: null
};

if ('insecureSkipTlsVerify' in options) {
this.requestOptions.strictSSL = !options.insecureSkipTlsVerify;
}
if ('timeout' in options) {
this.requestOptions.timeout = options.timeout;
}

this.authProvider = {
type: null
};
if (options.auth) {
this.requestOptions.auth = options.auth;
if (options.auth.provider) {
Expand Down

0 comments on commit 6a9f06d

Please sign in to comment.