diff --git a/src/MAOToolkit/Extensions/HttpContentExtensions.cs b/src/MAOToolkit/Extensions/HttpContentExtensions.cs index dded641..37febb9 100644 --- a/src/MAOToolkit/Extensions/HttpContentExtensions.cs +++ b/src/MAOToolkit/Extensions/HttpContentExtensions.cs @@ -15,16 +15,12 @@ public static class HttpContentExtensions /// String representation of HTTP content. public static async Task ReadAsStringAsync(this HttpContent httpContent, int charsLimit) { - if (httpContent is null) - throw new ArgumentNullException(nameof(httpContent)); + ArgumentNullException.ThrowIfNull(httpContent); + await httpContent.LoadIntoBufferAsync(); + var stream = await httpContent.ReadAsStreamAsync(); - if (!stream.CanRead) - { - return (await httpContent.ReadAsStringAsync()).Left(charsLimit); - } - // The `leaveOpen` should be `true` if there's another function going to be invoked AFTER this. using var reader = new StreamReader( stream, diff --git a/src/MAOToolkit/Extensions/StreamReaderExtensions.cs b/src/MAOToolkit/Extensions/StreamReaderExtensions.cs index 93fad3e..9c962fd 100644 --- a/src/MAOToolkit/Extensions/StreamReaderExtensions.cs +++ b/src/MAOToolkit/Extensions/StreamReaderExtensions.cs @@ -11,8 +11,7 @@ public static class StreamReaderExtensions /// String representation of readed stream. public static async ValueTask ReadWithLimitAsync(this StreamReader reader, int charsLimit) { - if (reader is null) - throw new ArgumentNullException(nameof(reader)); + ArgumentNullException.ThrowIfNull(reader); if (charsLimit > 0) {