Skip to content

Commit

Permalink
Merge branches 'dev' and 'dev' of https://github.com/tmenier/Flurl in…
Browse files Browse the repository at this point in the history
…to dev
  • Loading branch information
Todd committed Jan 17, 2024
2 parents e0f915a + 4daa713 commit 66535aa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Flurl.Http/Configuration/DefaultJsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public DefaultJsonSerializer(JsonSerializerOptions options = null) {
/// Deserializes the specified stream to an object of type T.
/// </summary>
/// <param name="stream">The stream to deserialize.</param>
public T Deserialize<T>(Stream stream) => stream.Length == 0 ? default : JsonSerializer.Deserialize<T>(stream, _options);
public T Deserialize<T>(Stream stream) => stream.CanSeek && stream.Length == 0
? default
: JsonSerializer.Deserialize<T>(stream, _options);
}
}
13 changes: 13 additions & 0 deletions test/Flurl.Test/Http/RealHttpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Dictionary<string, object>>(completionOption);

Assert.AreEqual(true, ((JsonElement)result["gzipped"]).GetBoolean());
}

[Test]
public async Task can_get_stream() {
using (var stream = await "https://www.google.com".GetStreamAsync())
Expand Down

0 comments on commit 66535aa

Please sign in to comment.