3.84Custom Extensions for Other Builders
Created on Aug 17, 2026~2 min read
The following builders all derive from the HttpRequestBuilderConfigurator<THttpBuilder> abstract type:
HttpFileDownloadBuilderHttpFileUploadBuilderHttpLongPollingBuilderHttpServerSentEventsBuilderHttpStressTestHarnessBuilder
These builders share a unified extension mechanism. For example, they all support configuring additional request parameters for the underlying HttpRequestBuilder through the With(builder => { ... }) method.
HttpRequestBuilderConfigurator<THttpBuilder> already includes some common methods (such as Profiler()). If you need to extend it further, you can write extension methods as follows:
public static class HttpRequestBuilderConfiguratorExtensions{ /// <summary> /// Throws an exception when the HTTP response's IsSuccessStatusCode property is <c>false</c>. /// </summary> /// <param name="configurator"> /// <see cref="HttpRequestBuilderConfigurator{THttpBuilder}" /> /// </param> /// <typeparam name="THttpBuilder">The concrete type of the derived builder</typeparam> /// <returns>Returns the builder instance itself, supporting chained calls.</returns> public static THttpBuilder EnsureSuccessStatusCode<THttpBuilder>(this HttpRequestBuilderConfigurator<THttpBuilder> configurator) where THttpBuilder : HttpRequestBuilderConfigurator<THttpBuilder> { return configurator.With(builder => builder.EnsureSuccessStatusCode()); }}In this way, all of the above builders can directly call the EnsureSuccessStatusCode() method and return the builder instance itself, maintaining a fluent chained-call experience.