Skip to content

Commit

Permalink
[core-https] Fix decoding of gzip responses (#13605)
Browse files Browse the repository at this point in the history
#13266 accidentally flipped a boolean, causing gzip responses to not be properly decoded. This PR fixes the issue and changes the code to make it less convoluted.

Also fixes the version string used by the User-Agent policy and finishes removing some old API surface that #13266 forgot to clean up.
  • Loading branch information
xirzec authored Feb 5, 2021
1 parent dfb933d commit e5af5c2
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 17 deletions.
1 change: 0 additions & 1 deletion sdk/core/core-https/review/core-https.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ export interface PipelineRequestOptions {
onUploadProgress?: (progress: TransferProgressEvent) => void;
proxySettings?: ProxySettings;
requestId?: string;
skipDecompressResponse?: boolean;
spanOptions?: SpanOptions;
streamResponseStatusCodes?: Set<number>;
timeout?: number;
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/core-https/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export const SDK_VERSION: string = "1.0.0-preview.1";
export const SDK_VERSION: string = "1.0.0-beta.1";
11 changes: 3 additions & 8 deletions sdk/core/core-https/src/nodeHttpsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class NodeHttpsClient implements HttpsClient {
request
};

let responseStream = getResponseStream(res, headers, shouldDecompress);
let responseStream = shouldDecompress ? getDecodedResponseStream(res, headers) : res;

const onDownloadProgress = request.onDownloadProgress;
if (onDownloadProgress) {
Expand Down Expand Up @@ -249,15 +249,10 @@ function getResponseHeaders(res: IncomingMessage): HttpHeaders {
return headers;
}

function getResponseStream(
function getDecodedResponseStream(
stream: IncomingMessage,
headers: HttpHeaders,
skipDecompressResponse = false
headers: HttpHeaders
): NodeJS.ReadableStream {
if (skipDecompressResponse) {
return stream;
}

const contentEncoding = headers.get("Content-Encoding");
if (contentEncoding === "gzip") {
const unzip = zlib.createGunzip();
Expand Down
7 changes: 0 additions & 7 deletions sdk/core/core-https/src/pipelineRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,6 @@ export interface PipelineRequestOptions {
*/
keepAlive?: boolean;

/**
* Disable automatic decompression based on Accept-Encoding header (Node only)
*/
skipDecompressResponse?: boolean;

/**
* Used to abort the request later.
*/
Expand Down Expand Up @@ -113,7 +108,6 @@ class PipelineRequestImpl implements PipelineRequest {
public streamResponseStatusCodes?: Set<number>;
public proxySettings?: ProxySettings;
public keepAlive: boolean;
public skipDecompressResponse: boolean;
public abortSignal?: AbortSignalLike;
public requestId: string;
public spanOptions?: SpanOptions;
Expand All @@ -129,7 +123,6 @@ class PipelineRequestImpl implements PipelineRequest {
this.formData = options.formData;
this.keepAlive = options.keepAlive ?? true;
this.proxySettings = options.proxySettings;
this.skipDecompressResponse = options.skipDecompressResponse ?? false;
this.streamResponseStatusCodes = options.streamResponseStatusCodes;
this.withCredentials = options.withCredentials ?? false;
this.abortSignal = options.abortSignal;
Expand Down

0 comments on commit e5af5c2

Please sign in to comment.