From 499f868a5168af7b1e00f4c36318a31a4985aa68 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Wed, 16 Jun 2021 18:54:56 -0500 Subject: [PATCH 1/2] Make content stream unseekable --- .../Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs b/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs index b4450bb425641..1a1f573e9a4c2 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs @@ -375,6 +375,12 @@ public void Dispose() } } + private sealed class BrowserUnseekableStream : MemoryStream { + public BrowserUnseekableStream (byte [] data) : base (data, writable: false) { } + + public override bool CanSeek => false; + } + private sealed class BrowserHttpContent : HttpContent { private byte[]? _data; @@ -407,7 +413,7 @@ private async Task GetResponseData() protected override async Task CreateContentReadStreamAsync() { byte[] data = await GetResponseData().ConfigureAwait(continueOnCapturedContext: true); - return new MemoryStream(data, writable: false); + return new BrowserUnseekableStream (data); } protected override Task SerializeToStreamAsync(Stream stream, TransportContext? context) => From 265e1e08d5a0f48bc7afb5c2896d1b7f43b3902f Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Wed, 16 Jun 2021 21:14:27 -0500 Subject: [PATCH 2/2] Update BrowserHttpHandler.cs --- .../System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs b/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs index 1a1f573e9a4c2..c187e80d15f90 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs @@ -220,7 +220,6 @@ protected internal override async Task SendAsync(HttpReques requestObject.SetObjectProperty("headers", jsHeaders); } - WasmHttpReadStream? wasmHttpReadStream = null; JSObject abortController = new HostObject("AbortController"); @@ -375,9 +374,9 @@ public void Dispose() } } - private sealed class BrowserUnseekableStream : MemoryStream { + private sealed class BrowserUnseekableStream : MemoryStream + { public BrowserUnseekableStream (byte [] data) : base (data, writable: false) { } - public override bool CanSeek => false; }