Skip to content

Commit

Permalink
Explicitly set Content-Length on package upload when possible. Fixes #15
Browse files Browse the repository at this point in the history
  • Loading branch information
gdivis committed Jan 11, 2019
1 parent a1f1bb9 commit 6b921d3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Inedo.UPack/Net/DefaultApiTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ public override async Task<ApiResponse> 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);
Expand Down
2 changes: 1 addition & 1 deletion src/Inedo.UPack/Net/UniversalFeedClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public async Task<Stream> GetPackageFileStreamAsync(UniversalPackageId id, Unive
/// <summary>
/// Uploads the package in the specified stream to the feed.
/// </summary>
/// <param name="stream">Stream containg a universal package.</param>
/// <param name="stream">Stream containing a universal package.</param>
/// <param name="cancellationToken">Cancellation token for asynchronous operations.</param>
/// <exception cref="ArgumentNullException"><paramref name="stream"/> is null.</exception>
public async Task UploadPackageAsync(Stream stream, CancellationToken cancellationToken)
Expand Down

0 comments on commit 6b921d3

Please sign in to comment.