Skip to content

Commit 79605e0

Browse files
committed
Fix configure await on Helpers MakeRequest
1 parent 4ff9df5 commit 79605e0

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

Storage/Extensions/HttpClientProgress.cs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,39 +27,36 @@ internal static class HttpClientProgress
2727
}
2828
}
2929

30-
using (var response = await client.SendAsync(message, HttpCompletionOption.ResponseHeadersRead))
30+
using var response = await client.SendAsync(message, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
31+
if (!response.IsSuccessStatusCode)
3132
{
32-
if (!response.IsSuccessStatusCode)
33+
var content = await response.Content.ReadAsStringAsync();
34+
var errorResponse = JsonConvert.DeserializeObject<ErrorResponse>(content);
35+
var e = new SupabaseStorageException(errorResponse?.Message ?? content)
3336
{
34-
var content = await response.Content.ReadAsStringAsync();
35-
var errorResponse = JsonConvert.DeserializeObject<ErrorResponse>(content);
36-
var e = new SupabaseStorageException(errorResponse?.Message ?? content)
37-
{
38-
Content = content,
39-
Response = response,
40-
StatusCode = errorResponse?.StatusCode ?? (int)response.StatusCode
41-
};
37+
Content = content,
38+
Response = response,
39+
StatusCode = errorResponse?.StatusCode ?? (int)response.StatusCode
40+
};
4241

43-
e.AddReason();
44-
throw e;
45-
}
42+
e.AddReason();
43+
throw e;
44+
}
4645

47-
var contentLength = response.Content.Headers.ContentLength;
48-
using (var download = await response.Content.ReadAsStreamAsync())
49-
{
50-
// no progress... no contentLength... very sad
51-
if (progress is null || !contentLength.HasValue)
52-
{
53-
await download.CopyToAsync(destination);
54-
return destination;
55-
}
56-
57-
// Such progress and contentLength much reporting Wow!
58-
var progressWrapper = new Progress<long>(totalBytes => progress.Report(GetProgressPercentage(totalBytes, contentLength.Value)));
59-
await download.CopyToAsync(destination, 81920, progressWrapper, cancellationToken);
60-
}
46+
var contentLength = response.Content.Headers.ContentLength;
47+
using var download = await response.Content.ReadAsStreamAsync();
48+
49+
// no progress... no contentLength... very sad
50+
if (progress is null || !contentLength.HasValue)
51+
{
52+
await download.CopyToAsync(destination);
53+
return destination;
6154
}
6255

56+
// Such progress and contentLength much reporting Wow!
57+
var progressWrapper = new Progress<long>(totalBytes => progress.Report(GetProgressPercentage(totalBytes, contentLength.Value)));
58+
await download.CopyToAsync(destination, 81920, progressWrapper, cancellationToken);
59+
6360
float GetProgressPercentage(float totalBytes, float currentBytes) => (totalBytes / currentBytes) * 100f;
6461

6562
return destination;

Storage/Helpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static async Task<HttpResponseMessage> MakeRequest(HttpMethod method, str
8686
requestMessage.Headers.TryAddWithoutValidation(kvp.Key, kvp.Value);
8787
}
8888

89-
var response = await HttpRequestClient!.SendAsync(requestMessage, cancellationToken);
89+
using var response = await HttpRequestClient!.SendAsync(requestMessage, cancellationToken).ConfigureAwait(false);
9090

9191
var content = await response.Content.ReadAsStringAsync();
9292

0 commit comments

Comments
 (0)