Skip to content

Commit

Permalink
add timeout configuration setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Huachao committed May 18, 2016
1 parent fde6c97 commit 81d94ad
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/controllers/requestController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
6 changes: 6 additions & 0 deletions src/models/configurationSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -26,5 +28,9 @@ export class RestClientSettings implements IRestClientSettings {
this.clearOutput = restClientSettings.get<boolean>("clearoutput", false);
this.followRedirect = restClientSettings.get<boolean>("followredirect", true);
this.defaultUserAgent = restClientSettings.get<string>("defaultuseragent", "vscode-restclient");
this.timeoutInMilliseconds = restClientSettings.get<number>("timeoutinmilliseconds", 0);
if (this.timeoutInMilliseconds < 0) {
this.timeoutInMilliseconds = 0;
}
}
}

0 comments on commit 81d94ad

Please sign in to comment.