From 91183a999a79e28ecacaa7f1e2ccb8d94dcb39ae Mon Sep 17 00:00:00 2001 From: Huachao Mao Date: Wed, 31 Oct 2018 10:34:06 +0800 Subject: [PATCH] Decode gzip encoding when Accept-Encoding header exists in request header #282 --- package.json | 3 ++- src/models/configurationSettings.ts | 6 +++++- src/utils/httpClient.ts | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8c1c29e2..3fa1c9c4 100644 --- a/package.json +++ b/package.json @@ -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." diff --git a/src/models/configurationSettings.ts b/src/models/configurationSettings.ts index e7a36d63..5490ee58 100644 --- a/src/models/configurationSettings.ts +++ b/src/models/configurationSettings.ts @@ -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("followredirect", true); - this.defaultHeaders = restClientSettings.get("defaultHeaders", {"User-Agent": "vscode-restclient"}); + this.defaultHeaders = restClientSettings.get("defaultHeaders", + { + "User-Agent": "vscode-restclient", + "Accept-Encoding": "gzip" + }); this.showResponseInDifferentTab = restClientSettings.get("showResponseInDifferentTab", false); this.rememberCookiesForSubsequentRequests = restClientSettings.get("rememberCookiesForSubsequentRequests", true); this.timeoutInMilliseconds = restClientSettings.get("timeoutinmilliseconds", 0); diff --git a/src/utils/httpClient.ts b/src/utils/httpClient.ts index e90791df..d290418a 100644 --- a/src/utils/httpClient.ts +++ b/src/utils/httpClient.ts @@ -211,6 +211,11 @@ export class HttpClient { } } + const acceptEncoding = getHeader(options.headers, 'Accept-Encoding'); + if (acceptEncoding && acceptEncoding.includes('gzip')) { + options.gzip = true; + } + return options; }