better support of raw data transfer

This commit is contained in:
Pilzinsel64
2025-03-18 08:56:08 +01:00
parent 86154e93af
commit 24cde0bd03
3 changed files with 21 additions and 1 deletions

View File

@@ -55,7 +55,16 @@ public class ApiClient(string apiUrl) : IApiClient
TResponse? result = null;
if (res.IsSuccessStatusCode)
result = serializer.Deserialize(await res.Content.ReadAsStringAsync(), typeof(TResponse)) as TResponse;
{
var mediaType = res.Content.Headers.ContentType?.MediaType;
if (!string.IsNullOrWhiteSpace(mediaType))
{
if (mediaType == "application/json")
result = serializer.Deserialize(await res.Content.ReadAsStringAsync(), typeof(TResponse)) as TResponse;
else if (typeof(TResponse).IsAssignableTo(typeof(ApiRawMessage)) && mediaType == "application/octet-stream")
result = (TResponse)(object)new ApiRawMessage(await res.Content.ReadAsByteArrayAsync());
}
}
return new(res, result);
}