Override SerializeToStreamAsync(..., cancellationToken) on Utf8StringContent (#32987)
authorStephen Toub <stoub@microsoft.com>
Fri, 6 Mar 2020 01:19:41 +0000 (20:19 -0500)
committerGitHub <noreply@github.com>
Fri, 6 Mar 2020 01:19:41 +0000 (20:19 -0500)
src/libraries/System.Utf8String.Experimental/ref/System.Utf8String.Experimental.cs
src/libraries/System.Utf8String.Experimental/src/System/Net/Http/Utf8StringContent.cs

index e9b443d76f3f68c8e6d6b9188033bad805da6f10..a6a2339b633fb3724cbed8403ce72804a6962af4 100644 (file)
@@ -277,6 +277,7 @@ namespace System.Net.Http
         public Utf8StringContent(System.Utf8String content, string? mediaType) { }
         protected override System.Threading.Tasks.Task<System.IO.Stream> CreateContentReadStreamAsync() { throw null; }
         protected override System.Threading.Tasks.Task SerializeToStreamAsync(System.IO.Stream stream, System.Net.TransportContext? context) { throw null; }
+        protected override System.Threading.Tasks.Task SerializeToStreamAsync(System.IO.Stream stream, System.Net.TransportContext? context, System.Threading.CancellationToken cancellationToken) { throw null; }
         protected override bool TryComputeLength(out long length) { throw null; }
     }
 }
index 8fa7c7992c0de86c8cd5adcf5f2cac2a112d72b9..5f7ab00395b15bf9ab469360cee97b3fd372a2b6 100644 (file)
@@ -4,6 +4,7 @@
 
 using System.IO;
 using System.Net.Http.Headers;
+using System.Threading;
 using System.Threading.Tasks;
 
 namespace System.Net.Http
@@ -36,15 +37,14 @@ namespace System.Net.Http
             };
         }
 
-        protected override Task<Stream> CreateContentReadStreamAsync()
-        {
-            return Task.FromResult<Stream>(new Utf8StringStream(_content));
-        }
+        protected override Task<Stream> CreateContentReadStreamAsync() =>
+            Task.FromResult<Stream>(new Utf8StringStream(_content));
 
-        protected override Task SerializeToStreamAsync(Stream stream, TransportContext? context)
-        {
-            return stream.WriteAsync(_content.AsMemoryBytes()).AsTask();
-        }
+        protected override Task SerializeToStreamAsync(Stream stream, TransportContext? context) =>
+            SerializeToStreamAsync(stream, context, default);
+
+        protected override Task SerializeToStreamAsync(Stream stream, TransportContext? context, CancellationToken cancellationToken) =>
+            stream.WriteAsync(_content.AsMemoryBytes(), cancellationToken).AsTask();
 
         protected override bool TryComputeLength(out long length)
         {