From 6b921d37f0133605764a74340555a1f9e61f3e4a Mon Sep 17 00:00:00 2001 From: Greg D Date: Thu, 10 Jan 2019 23:35:23 -0500 Subject: [PATCH] Explicitly set Content-Length on package upload when possible. Fixes #15 --- src/Inedo.UPack/Net/DefaultApiTransport.cs | 7 ++++++- src/Inedo.UPack/Net/UniversalFeedClient.cs | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Inedo.UPack/Net/DefaultApiTransport.cs b/src/Inedo.UPack/Net/DefaultApiTransport.cs index 9d40f02..be04078 100644 --- a/src/Inedo.UPack/Net/DefaultApiTransport.cs +++ b/src/Inedo.UPack/Net/DefaultApiTransport.cs @@ -41,7 +41,12 @@ public override async Task GetResponseAsync(ApiRequest request, Can if (request.RequestBody != null) { - webRequest.AllowWriteStreamBuffering = false; + if (request.RequestBody.CanSeek) + { + webRequest.AllowWriteStreamBuffering = false; + webRequest.ContentLength = request.RequestBody.Length - request.RequestBody.Position; + } + using (var requestStream = await webRequest.GetRequestStreamAsync().ConfigureAwait(false)) { await request.RequestBody.CopyToAsync(requestStream, 81920, cancellationToken).ConfigureAwait(false); diff --git a/src/Inedo.UPack/Net/UniversalFeedClient.cs b/src/Inedo.UPack/Net/UniversalFeedClient.cs index b2611fd..e36dad0 100644 --- a/src/Inedo.UPack/Net/UniversalFeedClient.cs +++ b/src/Inedo.UPack/Net/UniversalFeedClient.cs @@ -345,7 +345,7 @@ public async Task GetPackageFileStreamAsync(UniversalPackageId id, Unive /// /// Uploads the package in the specified stream to the feed. /// - /// Stream containg a universal package. + /// Stream containing a universal package. /// Cancellation token for asynchronous operations. /// is null. public async Task UploadPackageAsync(Stream stream, CancellationToken cancellationToken)