Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tmenier committed Dec 20, 2022
1 parent d562a5e commit a1ef2c8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Flurl.Http/FlurlResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public class FlurlResponse : IFlurlResponse
if (ct?.CharSet != null)
ct.CharSet = ct.CharSet.StripQuotes();

_capturedBody = await ResponseMessage.Content.ReadAsStringAsync();
_capturedBody = await ResponseMessage.Content.ReadAsStringAsync().ConfigureAwait(false);
_streamRead = true;
return (string)_capturedBody;
}
Expand Down
21 changes: 9 additions & 12 deletions src/Flurl.Http/ResponseExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ public static class ResponseExtensions
/// <example>x = await url.PostAsync(data).ReceiveJson&lt;T&gt;()</example>
/// <exception cref="FlurlHttpException">Condition.</exception>
public static async Task<T> ReceiveJson<T>(this Task<IFlurlResponse> response) {
using (var resp = await response.ConfigureAwait(false)) {
if (resp == null) return default;
return await resp.GetJsonAsync<T>().ConfigureAwait(false);
}
using var resp = await response.ConfigureAwait(false);
if (resp == null) return default;
return await resp.GetJsonAsync<T>().ConfigureAwait(false);
}

/// <summary>
Expand All @@ -30,10 +29,9 @@ public static class ResponseExtensions
/// <returns>A Task whose result is the response body as a string.</returns>
/// <example>s = await url.PostAsync(data).ReceiveString()</example>
public static async Task<string> ReceiveString(this Task<IFlurlResponse> response) {
using (var resp = await response.ConfigureAwait(false)) {
if (resp == null) return null;
return await resp.GetStringAsync().ConfigureAwait(false);
}
using var resp = await response.ConfigureAwait(false);
if (resp == null) return null;
return await resp.GetStringAsync().ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -61,10 +59,9 @@ public static class ResponseExtensions
/// <returns>A Task whose result is the response body as a byte array.</returns>
/// <example>bytes = await url.PostAsync(data).ReceiveBytes()</example>
public static async Task<byte[]> ReceiveBytes(this Task<IFlurlResponse> response) {
using (var resp = await response.ConfigureAwait(false)) {
if (resp == null) return null;
return await resp.GetBytesAsync().ConfigureAwait(false);
}
using var resp = await response.ConfigureAwait(false);
if (resp == null) return null;
return await resp.GetBytesAsync().ConfigureAwait(false);
}
}
}

0 comments on commit a1ef2c8

Please sign in to comment.