diff --git a/README.md b/README.md index 1415fd2..3124b13 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,8 @@ var convertapi = require('convertapi')('your-api-secret', { username: 'testuser', password: 'secret' } - } + }, + keepAlive: true }); ``` diff --git a/index.d.ts b/index.d.ts index d2aded7..4b55c84 100644 --- a/index.d.ts +++ b/index.d.ts @@ -5,6 +5,7 @@ export interface Options { downloadTimeout?: number; proxy?: object; baseUri?: string; + keepAlive?: boolean; } export interface ResultFile { diff --git a/src/client.js b/src/client.js index 48c4ced..ef24110 100644 --- a/src/client.js +++ b/src/client.js @@ -1,5 +1,6 @@ import axios from 'axios'; import fs from 'fs'; +import https from 'https'; import { buildQueryString, encodeFileName } from './utils'; import UploadResult from './upload_result'; import Error from './error'; @@ -91,6 +92,7 @@ export default class Client { maxBodyLength: Infinity, timeout: this.api.uploadTimeout * 1000, proxy: this.api.proxy, + httpsAgent: new https.Agent({ keepAlive: this.api.keepAlive }), }; return axios(options) diff --git a/src/index.js b/src/index.js index 5f24d48..d6f911e 100644 --- a/src/index.js +++ b/src/index.js @@ -17,6 +17,7 @@ function ConvertAPI(secret, options = {}) { this.downloadTimeout = options.downloadTimeout || 1800; this.userAgent = `ConvertAPI-Node/${pkg.version}`; this.proxy = options.proxy; + this.keepAlive = options.keepAlive !== undefined ? options.keepAlive : true; this.client = new Client(this); }