Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core-https] Fix some issues with streams in NodeHttpsClient #11929

Merged
merged 1 commit into from
Oct 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions sdk/core/core-https/src/nodeHttpsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,20 @@ export class NodeHttpsClient implements HttpsClient {
}
}

if (body && request.onUploadProgress) {
const onUploadProgress = request.onUploadProgress;
const uploadReportStream = new ReportTransform(onUploadProgress);
if (isReadableStream(body)) {
body.pipe(uploadReportStream);
} else {
uploadReportStream.end(body);
}

body = uploadReportStream;
}

try {
const result = await new Promise<PipelineResponse>((resolve, reject) => {
if (body && request.onUploadProgress) {
const onUploadProgress = request.onUploadProgress;
const uploadReportStream = new ReportTransform(onUploadProgress);
uploadReportStream.on("error", reject);
if (isReadableStream(body)) {
body.pipe(uploadReportStream);
} else {
uploadReportStream.end(body);
}

body = uploadReportStream;
}
const options = this.getRequestOptions(request);
const req = https.request(options, async (res) => {
const headers = getResponseHeaders(res);
Expand All @@ -123,6 +123,7 @@ export class NodeHttpsClient implements HttpsClient {
const onDownloadProgress = request.onDownloadProgress;
if (onDownloadProgress) {
const downloadReportStream = new ReportTransform(onDownloadProgress);
downloadReportStream.on("error", reject);
responseStream.pipe(downloadReportStream);
responseStream = downloadReportStream;
}
Expand All @@ -144,14 +145,14 @@ export class NodeHttpsClient implements HttpsClient {
reject(new AbortError("The operation was aborted."));
}
});
if (body) {
if (isReadableStream(body)) {
body.pipe(req);
} else {
req.write(body);
}
if (body && isReadableStream(body)) {
mikeharder marked this conversation as resolved.
Show resolved Hide resolved
body.pipe(req);
} else if (body) {
req.end(body);
} else {
// streams don't like "undefined" being passed as data
req.end();
}
req.end();
});
return result;
} finally {
Expand Down