[System.Net.Http]: Close request stream when HttpClientHandler.SendAsync() is done...
authorMartin Baulig <mabaul@microsoft.com>
Tue, 18 Jul 2017 15:09:37 +0000 (11:09 -0400)
committerGitHub <noreply@github.com>
Tue, 18 Jul 2017 15:09:37 +0000 (11:09 -0400)
mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.cs

index 4aeaf50cd931ec9a513c0d4da69bb30f1bfe1e15..8ea06b162bc4fd841e3be8a83440ca836763553a 100644 (file)
@@ -375,8 +375,9 @@ namespace System.Net.Http
 
                                                wrequest.ResendContentFactory = content.CopyTo;
 
-                                               var stream = await wrequest.GetRequestStreamAsync ().ConfigureAwait (false);
-                                               await request.Content.CopyToAsync (stream).ConfigureAwait (false);
+                                               using (var stream = await wrequest.GetRequestStreamAsync ().ConfigureAwait (false)) {
+                                                       await request.Content.CopyToAsync (stream).ConfigureAwait (false);
+                                               }
                                        } else if (HttpMethod.Post.Equals (request.Method) || HttpMethod.Put.Equals (request.Method) || HttpMethod.Delete.Equals (request.Method)) {
                                                // Explicitly set this to make sure we're sending a "Content-Length: 0" header.
                                                // This fixes the issue that's been reported on the forums: