Skip to content

Commit 823a137

Browse files
committed
Fix incorrect manipulation with streams resulting in exceptions.
1 parent bbd7e8c commit 823a137

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

AbuseIPDB/API.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public static async Task<HttpResponseMessage> Request
5151
else req.Content = content;
5252

5353
HttpResponseMessage res = await cl.SendAsync(req);
54+
content?.Dispose();
5455

5556
MediaTypeHeaderValue contentType = res.Content.Headers.ContentType;
5657
if (!absoluteUrl && contentType.MediaType != "application/json")

AbuseIPDB/Extensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ public static async Task<T> Deseralize<T>(this HttpResponseMessage res, JsonSeri
3939
/// <param name="options">Optional JSON serialization options object.</param>
4040
public static async Task<StreamContent> Serialize(this object obj, JsonSerializerOptions options = null)
4141
{
42-
using MemoryStream ms = new();
42+
MemoryStream ms = new();
4343
await JsonSerializer.SerializeAsync(ms, obj, options);
44+
ms.Position = 0;
4445

4546
StreamContent sc = new(ms);
46-
sc.Headers.ContentType = new("application/json; charset=utf-8");
47+
sc.Headers.ContentType = new("application/json");
4748

4849
return sc;
4950
}

0 commit comments

Comments
 (0)