Skip to content

Commit

Permalink
Decode gzip encoding when Accept-Encoding header exists in request he…
Browse files Browse the repository at this point in the history
…ader #282
  • Loading branch information
Huachao committed Oct 31, 2018
1 parent 9529fe6 commit 91183a9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@
"rest-client.defaultHeaders": {
"type": "object",
"default": {
"User-Agent": "vscode-restclient"
"User-Agent": "vscode-restclient",
"Accept-Encoding": "gzip"
},
"scope": "resource",
"description": "If particular headers are omitted in request header, these will be added as headers for each request."
Expand Down
6 changes: 5 additions & 1 deletion src/models/configurationSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ export class RestClientSettings implements IRestClientSettings {
const document = getCurrentTextDocument();
const restClientSettings = workspace.getConfiguration("rest-client", document ? document.uri : null);
this.followRedirect = restClientSettings.get<boolean>("followredirect", true);
this.defaultHeaders = restClientSettings.get<Headers>("defaultHeaders", {"User-Agent": "vscode-restclient"});
this.defaultHeaders = restClientSettings.get<Headers>("defaultHeaders",
{
"User-Agent": "vscode-restclient",
"Accept-Encoding": "gzip"
});
this.showResponseInDifferentTab = restClientSettings.get<boolean>("showResponseInDifferentTab", false);
this.rememberCookiesForSubsequentRequests = restClientSettings.get<boolean>("rememberCookiesForSubsequentRequests", true);
this.timeoutInMilliseconds = restClientSettings.get<number>("timeoutinmilliseconds", 0);
Expand Down
5 changes: 5 additions & 0 deletions src/utils/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ export class HttpClient {
}
}

const acceptEncoding = getHeader(options.headers, 'Accept-Encoding');
if (acceptEncoding && acceptEncoding.includes('gzip')) {
options.gzip = true;
}

return options;
}

Expand Down

0 comments on commit 91183a9

Please sign in to comment.