Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API that allows to remove all assigned handlers from the HTTP client #5801

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

rainsxng
Copy link
Contributor

@rainsxng rainsxng commented Jan 17, 2025

Background and motivation

.NET provides the ConfigureHttpClientDefaults method that allows you to configure the default behavior of the HttpClient. With the help of this method you can register the StandardResiliencePipeline as part of the default configuration of the HttpClient:

services.ConfigureHttpClientDefaults(builder => builder.AddStandardResilienceHandler());

This is convenient, since you don't need to configure the resilience pipeline for each HttpClient. But with the API we currently provide users face a few issues/challenges when they need to change the default configuration. This change focuses on the following issue:

Removing the existing default resilience pipeline and adding a custom one

For example, a user registers the StandardResilienceHandler as default configuration, but at the same time he/she wants to use the StandardHedgingHandler for a particular named HttpClient:

services.ConfigureHttpClientDefaults(builder => builder.AddStandardResilienceHandler());

// For a named HttpClient "custom" we want to remove the StandardResilienceHandler and add instead the StandardHedgingHandler.
services.AddHttpClient("custom")./*Remove StandardResilienceHandler*/.AddStandardHedgingHandler();

API description

This API provides functionality to remove all assigned handlers from the HttpClient.

API Usage

services.ConfigureHttpClientDefaults(builder => builder.AddStandardResilienceHandler());
// For a named HttpClient "custom" we want to remove the StandardResilienceHandler and add instead the StandardHedgingHandler.
services.AddHttpClient("custom")
    .RemoveAllResilienceHandlers()
    .AddStandardHedgingHandler();

This PR partially resolves #5695

Microsoft Reviewers: Open in CodeFlow

@rainsxng rainsxng added area-resilience api-approved API was approved in API review, it can be implemented labels Jan 17, 2025
@rainsxng rainsxng self-assigned this Jan 17, 2025
@rainsxng rainsxng requested a review from a team as a code owner January 17, 2025 15:12
@rainsxng rainsxng marked this pull request as draft January 17, 2025 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-approved API was approved in API review, it can be implemented area-resilience
Projects
None yet
1 participant