From c99e708c9b7de1231a114af1bfa099ef5848c6fa Mon Sep 17 00:00:00 2001 From: David Pine Date: Mon, 24 Jul 2023 08:20:08 -0500 Subject: [PATCH] No need for the length limit read stream. --- .../Json/HttpClientJsonExtensions.Get.AsyncEnumerable.cs | 6 +----- .../src/System/Net/Http/Json/LengthLimitReadStream.cs | 2 -- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpClientJsonExtensions.Get.AsyncEnumerable.cs b/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpClientJsonExtensions.Get.AsyncEnumerable.cs index 5472332e17574..36cad11275e60 100644 --- a/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpClientJsonExtensions.Get.AsyncEnumerable.cs +++ b/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/HttpClientJsonExtensions.Get.AsyncEnumerable.cs @@ -172,14 +172,10 @@ public static partial class HttpClientJsonExtensions using Stream contentStream = await HttpContentJsonExtensions.GetContentStreamAsync( response.Content, cancellationToken).ConfigureAwait(false); - using LengthLimitReadStream readStream = new(contentStream, (int)client.MaxResponseContentBufferSize); - await foreach (TValue? value in JsonSerializer.DeserializeAsyncEnumerable( - readStream, jsonTypeInfo, cancellationToken).ConfigureAwait(false)) + contentStream, jsonTypeInfo, cancellationToken).ConfigureAwait(false)) { yield return value; - - readStream.ResetCount(); } } } diff --git a/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/LengthLimitReadStream.cs b/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/LengthLimitReadStream.cs index aed46ff7ef96f..9837587958a92 100644 --- a/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/LengthLimitReadStream.cs +++ b/src/libraries/System.Net.Http.Json/src/System/Net/Http/Json/LengthLimitReadStream.cs @@ -33,8 +33,6 @@ internal static void ThrowExceededBufferLimit(int limit) throw new HttpRequestException(SR.Format(SR.net_http_content_buffersize_exceeded, limit)); } - internal void ResetCount() => _remainingLength = _lengthLimit; - public override bool CanRead => _innerStream.CanRead; public override bool CanSeek => _innerStream.CanSeek; public override bool CanWrite => false;