-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Milestone
Description
Background and Motivation
While checking for other usages of ReadAsStringAsync()
when working on #41531, I found one other occurrence here:
aspnetcore/src/Http/WebUtilities/src/FormMultipartSection.cs
Lines 56 to 59 in c85baf8
public Task<string> GetValueAsync() | |
{ | |
return Section.ReadAsStringAsync(); | |
} |
As well as adding an overload for a CancellationToken
parameter there, another would be needed here:
/// <summary> | |
/// Reads the body of the section as a string | |
/// </summary> | |
/// <param name="section">The section to read from</param> | |
/// <returns>The body steam as string</returns> | |
public static async Task<string> ReadAsStringAsync(this MultipartSection section) |
The new overload could then be used here:
var value = await formDataSection.GetValueAsync(); |
Proposed API
namespace Microsoft.AspNetCore.WebUtilities;
public class FormMultipartSection
{
+ public Task<string> GetValueAsync(CancellationToken cancellationToken);
}
public static class MultipartSectionStreamExtensions
{
+ public static async Task<string> ReadAsStringAsync(this MultipartSection section, CancellationToken cancellationToken);
}
Usage Examples
var formDataSection = new FormMultipartSection(section, contentDisposition);
var key = formDataSection.Name;
var value = await formDataSection.GetValueAsync(cancellationToken);
Alternative Designs
Add an optional parameter instead as a binary-breaking change for .NET 7.
namespace Microsoft.AspNetCore.WebUtilities;
public class FormMultipartSection
{
- public Task<string> GetValueAsync();
+ public Task<string> GetValueAsync(CancellationToken cancellationToken = default);
}
public static class MultipartSectionStreamExtensions
{
- public static async Task<string> ReadAsStringAsync(this MultipartSection section);
+ public static async Task<string> ReadAsStringAsync(this MultipartSection section, CancellationToken cancellationToken = default);
}
Risks
None known.
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions