Skip to content

Commit

Permalink
Add request compression option (microsoft#1203)
Browse files Browse the repository at this point in the history
Co-authored-by: Grzegorz Gurgul (from Dev Box) <ggurgul@microsoft.com>
  • Loading branch information
kboom and Grzegorz Gurgul (from Dev Box) authored Nov 10, 2023
1 parent 329bfca commit 214ba0c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export interface IRequestOptions {
allowRedirects?: boolean,
maxRedirects?: number,
maxSockets?: number,
keepAlive?: boolean
keepAlive?: boolean,
requestCompressionForDownloads?: boolean
}

export interface IProxyConfiguration {
Expand Down
14 changes: 13 additions & 1 deletion Extensions/ArtifactEngine/Providers/webProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ArtifactItem[]> {
Expand Down Expand Up @@ -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;
});
Expand Down Expand Up @@ -145,5 +156,6 @@ export class WebProvider implements IArtifactProvider {
private rootItemsLocation: string;
private templateFile: string;
private variables: string;
private requestCompressionForDownloads: boolean;
public webClient: WebClient;
}

0 comments on commit 214ba0c

Please sign in to comment.