In ServiceStack's .NET 6+ builds, HTTP Utils create a lazy shared HttpClient. Set its handler factory during application initialization, before the first helper call:

ServiceStack.HttpUtils.HttpClientHandlerFactory = () =>
    new System.Net.Http.HttpClientHandler
    {
        UseProxy = true,
        Proxy = new System.Net.WebProxy("http://proxy.example:8080"),
        AutomaticDecompression =
            System.Net.DecompressionMethods.Brotli |
            System.Net.DecompressionMethods.Deflate |
            System.Net.DecompressionMethods.GZip
    };

If the shared client already exists, changing this factory does not reconfigure it. That timing is the first check when a later assignment appears ineffective. An HTTP endpoint from the HTTP proxy list can be chosen for a public route before that shared client is created.

For a proxy account, set WebProxy.Credentials through the application's configuration. HttpClientHandler.UseDefaultCredentials concerns the server account and does not automatically fill that proxy object's credentials.

An older HttpWebRequest requestFilter example targets the earlier implementation. In the newer form, request configuration covers request fields while the handler owns connection routing.

Keep an existing custom-client factory or application HTTP-client-factory ownership arrangement when one is already installed. This handler factory is a shared policy; simultaneous unrelated routes need separately owned clients.

متعلقہ مضامین