diff --git a/src/Flurl.Http/Configuration/DefaultJsonSerializer.cs b/src/Flurl.Http/Configuration/DefaultJsonSerializer.cs
index 580217cd..0bc346b3 100644
--- a/src/Flurl.Http/Configuration/DefaultJsonSerializer.cs
+++ b/src/Flurl.Http/Configuration/DefaultJsonSerializer.cs
@@ -35,6 +35,8 @@ public DefaultJsonSerializer(JsonSerializerOptions options = null) {
/// Deserializes the specified stream to an object of type T.
///
/// The stream to deserialize.
- public T Deserialize(Stream stream) => stream.Length == 0 ? default : JsonSerializer.Deserialize(stream, _options);
+ public T Deserialize(Stream stream) => stream.CanSeek && stream.Length == 0
+ ? default
+ : JsonSerializer.Deserialize(stream, _options);
}
}
\ No newline at end of file
diff --git a/test/Flurl.Test/Http/RealHttpTests.cs b/test/Flurl.Test/Http/RealHttpTests.cs
index 8bfca19c..98763281 100644
--- a/test/Flurl.Test/Http/RealHttpTests.cs
+++ b/test/Flurl.Test/Http/RealHttpTests.cs
@@ -60,6 +60,19 @@ public async Task can_post_and_receive_json() {
Assert.AreEqual(2, result.json["b"].GetInt32());
}
+ [Test]
+ [TestCase(HttpCompletionOption.ResponseHeadersRead)]
+ [TestCase(HttpCompletionOption.ResponseContentRead)]
+ public async Task can_get_json_with_http_completion_option_headers(HttpCompletionOption completionOption)
+ {
+ var result = await "https://httpbin.org"
+ .AppendPathSegment("gzip")
+ .WithHeader("Accept-encoding", "gzip")
+ .GetJsonAsync>(completionOption);
+
+ Assert.AreEqual(true, ((JsonElement)result["gzipped"]).GetBoolean());
+ }
+
[Test]
public async Task can_get_stream() {
using (var stream = await "https://www.google.com".GetStreamAsync())