diff --git a/Refit.Tests/ResponseTests.cs b/Refit.Tests/ResponseTests.cs index 0d57e8761..0b3136968 100644 --- a/Refit.Tests/ResponseTests.cs +++ b/Refit.Tests/ResponseTests.cs @@ -511,6 +511,7 @@ public sealed class ThrowOnGetLengthMemoryStream : MemoryStream { public bool CanGetLength { get; set; } + public override bool CanSeek { get => CanGetLength; } public override long Length => CanGetLength ? base.Length : throw new NotSupportedException(); } diff --git a/Refit/RequestBuilderImplementation.cs b/Refit/RequestBuilderImplementation.cs index 20092b544..8c1780977 100644 --- a/Refit/RequestBuilderImplementation.cs +++ b/Refit/RequestBuilderImplementation.cs @@ -452,6 +452,13 @@ CancellationToken cancellationToken } else { + using var stream = await content + .ReadAsStreamAsync(cancellationToken) + .ConfigureAwait(false); + if (stream.CanSeek) + { + await content.LoadIntoBufferAsync().ConfigureAwait(false); + } result = await serializer .FromHttpContentAsync(content, cancellationToken) .ConfigureAwait(false);