From 214ba0c8bc606499ce9e900031a596ccf1b9e7ac Mon Sep 17 00:00:00 2001 From: Grzegorz Gurgul Date: Fri, 10 Nov 2023 11:40:31 +0100 Subject: [PATCH] Add request compression option (#1203) Co-authored-by: Grzegorz Gurgul (from Dev Box) --- .../Providers/typed-rest-client/Interfaces.ts | 3 ++- Extensions/ArtifactEngine/Providers/webProvider.ts | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Extensions/ArtifactEngine/Providers/typed-rest-client/Interfaces.ts b/Extensions/ArtifactEngine/Providers/typed-rest-client/Interfaces.ts index 1de487101..f86a9d176 100644 --- a/Extensions/ArtifactEngine/Providers/typed-rest-client/Interfaces.ts +++ b/Extensions/ArtifactEngine/Providers/typed-rest-client/Interfaces.ts @@ -24,7 +24,8 @@ export interface IRequestOptions { allowRedirects?: boolean, maxRedirects?: number, maxSockets?: number, - keepAlive?: boolean + keepAlive?: boolean, + requestCompressionForDownloads?: boolean } export interface IProxyConfiguration { diff --git a/Extensions/ArtifactEngine/Providers/webProvider.ts b/Extensions/ArtifactEngine/Providers/webProvider.ts index 402a22a73..6af85e782 100644 --- a/Extensions/ArtifactEngine/Providers/webProvider.ts +++ b/Extensions/ArtifactEngine/Providers/webProvider.ts @@ -25,6 +25,7 @@ export class WebProvider implements IArtifactProvider { this.templateFile = templateFile; this.webClient = WebClientFactory.getClient([handler], requestOptions); this.variables = variables; + this.requestCompressionForDownloads = requestOptions ? requestOptions.requestCompressionForDownloads : false; } getRootItems(): Promise { @@ -52,7 +53,17 @@ export class WebProvider implements IArtifactProvider { var itemUrl: string = artifactItem.metadata['downloadUrl']; var zipStream = null; itemUrl = itemUrl.replace(/([^:]\/)\/+/g, "$1"); - this.webClient.get(itemUrl, contentType ? { 'Accept': contentType } : undefined).then((res: HttpClientResponse) => { + + const additionalHeaders = {}; + if (contentType) { + additionalHeaders['Accept'] = contentType + } + + if (this.requestCompressionForDownloads) { + additionalHeaders['Accept-Encoding'] = "gzip" + } + + this.webClient.get(itemUrl, additionalHeaders).then((res: HttpClientResponse) => { res.message.on('data', (chunk) => { downloadSize += chunk.length; }); @@ -145,5 +156,6 @@ export class WebProvider implements IArtifactProvider { private rootItemsLocation: string; private templateFile: string; private variables: string; + private requestCompressionForDownloads: boolean; public webClient: WebClient; } \ No newline at end of file