diff --git a/README.md b/README.md index 45281dc8..d28c5c73 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,9 @@ Each time we sent a http request, the request details(method, url, headers and b [MIT License](LICENSE) ## Change Log +### 0.2.1 +* __Add Configuration Setting__: Timeout in milliseconds, less or equal than 0 represents for infinity, default is `0` + ### 0.2.0 * Add http request history diff --git a/package.json b/package.json index 7f46726e..29b295fd 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "rest-client", "displayName": "REST Client", "description": "REST Client for Visual Studio Code", - "version": "0.2.0", + "version": "0.2.1", "publisher": "humao", "author": { "name": "Huachao Mao", @@ -77,6 +77,11 @@ "type": "string", "default": "vscode-restclient", "description": "If User-Agent header is omitted in request header, this value will be added as user agent for each request." + }, + "rest-client.timeoutinmilliseconds": { + "type": "integer", + "default": 0, + "description": "Timeout in milliseconds. 0 for infinity" } } } diff --git a/src/controllers/requestController.ts b/src/controllers/requestController.ts index 80220dfa..8f5015ba 100644 --- a/src/controllers/requestController.ts +++ b/src/controllers/requestController.ts @@ -84,6 +84,9 @@ export class RequestController { PersistUtility.save(httpRequest); }) .catch(error => { + if (error.code === 'ETIMEDOUT') { + error = `Error: Timed out in ${this._restClientSettings.timeoutInMilliseconds}ms according to your configuration 'rest-client.timeoutinmilliseconds'.`; + } this._statusBarItem.text = ''; this._outputChannel.appendLine(`${error}\n`); this._outputChannel.show(true); diff --git a/src/httpClient.ts b/src/httpClient.ts index 80a9d423..bd61a8b6 100644 --- a/src/httpClient.ts +++ b/src/httpClient.ts @@ -20,6 +20,7 @@ export class HttpClient { method: httpRequest.method, body: httpRequest.body, time: true, + timeout: this._settings.timeoutInMilliseconds, strictSSL: false, followRedirect: this._settings.followRedirect }; diff --git a/src/models/configurationSettings.ts b/src/models/configurationSettings.ts index 0b1a9fb7..286f5394 100644 --- a/src/models/configurationSettings.ts +++ b/src/models/configurationSettings.ts @@ -6,12 +6,14 @@ export interface IRestClientSettings { clearOutput: boolean; followRedirect: boolean; defaultUserAgent: string; + timeoutInMilliseconds: number; } export class RestClientSettings implements IRestClientSettings { clearOutput: boolean; followRedirect: boolean; defaultUserAgent: string; + timeoutInMilliseconds: number; constructor() { workspace.onDidChangeConfiguration(() => { @@ -26,5 +28,9 @@ export class RestClientSettings implements IRestClientSettings { this.clearOutput = restClientSettings.get("clearoutput", false); this.followRedirect = restClientSettings.get("followredirect", true); this.defaultUserAgent = restClientSettings.get("defaultuseragent", "vscode-restclient"); + this.timeoutInMilliseconds = restClientSettings.get("timeoutinmilliseconds", 0); + if (this.timeoutInMilliseconds < 0) { + this.timeoutInMilliseconds = 0; + } } } \ No newline at end of file