Show / Hide Table of Contents

Class HttpConfigurationBuilder

Contains methods for configuring the SDK's networking behavior.

Inheritance
System.Object
HttpConfigurationBuilder
Implements
IDiagnosticDescription
Namespace: LaunchDarkly.Sdk.Client.Integrations
Assembly: LaunchDarkly.ClientSdk.dll
Syntax
public sealed class HttpConfigurationBuilder : Object, IDiagnosticDescription
Remarks

If you want to set non-default values for any of these properties, create a builder with HttpConfiguration(), change its properties with the methods of this class, and pass it to Http(HttpConfigurationBuilder):

    var config = Configuration.Builder(sdkKey)
        .Http(
            Components.HttpConfiguration()
                .ConnectTimeout(TimeSpan.FromMilliseconds(3000))
        )
        .Build();

Constructors

HttpConfigurationBuilder()

Declaration
public HttpConfigurationBuilder()

Fields

DefaultConnectTimeout

The default value for ConnectTimeout(TimeSpan): 10 seconds.

Declaration
public static readonly TimeSpan DefaultConnectTimeout
Field Value
Type Description
System.TimeSpan

DefaultResponseStartTimeout

The default value for ResponseStartTimeout(TimeSpan): 10 seconds.

Declaration
public static readonly TimeSpan DefaultResponseStartTimeout
Field Value
Type Description
System.TimeSpan

Methods

ConnectTimeout(TimeSpan)

Sets the network connection timeout.

Declaration
public HttpConfigurationBuilder ConnectTimeout(TimeSpan connectTimeout)
Parameters
Type Name Description
System.TimeSpan connectTimeout

the timeout

Returns
Type Description
HttpConfigurationBuilder

the builder

Remarks

This is the time allowed for the underlying HTTP client to connect to the LaunchDarkly server, for any individual network connection.

It is not the same as the timeout parameter to Init(Configuration, Context, TimeSpan), which limits the time for initializing the SDK regardless of how many individual HTTP requests are done in that time.

Not all .NET platforms support setting a connection timeout. It is supported in .NET Core 2.1+, .NET 5+, and Xamarin Android, but not in Xamarin iOS. On platforms where it is not supported, only ResponseStartTimeout(TimeSpan) will be used.

Also, since this is implemented (on supported platforms) as part of the standard HttpMessageHandler implementation for those platforms, if you have specified some other HTTP handler implementation with System.Net.Http.HttpMessageHandler, the ConnectTimeout(TimeSpan) here will be ignored.

See Also
ResponseStartTimeout(TimeSpan)

CreateHttpConfiguration(LdClientContext)

Called internally by the SDK to create an implementation instance. Applications do not need to call this method.

Declaration
public HttpConfiguration CreateHttpConfiguration(LdClientContext context)
Parameters
Type Name Description
LdClientContext context

provides SDK configuration data

Returns
Type Description
HttpConfiguration

an HttpConfiguration

CustomHeader(String, String)

Specifies a custom HTTP header that should be added to all SDK requests.

Declaration
public HttpConfigurationBuilder CustomHeader(string name, string value)
Parameters
Type Name Description
System.String name

the header name

System.String value

the header value

Returns
Type Description
HttpConfigurationBuilder

the builder

Remarks

This may be helpful if you are using a gateway or proxy server that requires a specific header in requests. You may add any number of headers.

DescribeConfiguration(LdClientContext)

Called internally by the SDK to inspect the configuration. Applications do not need to call this method.

Declaration
public LdValue DescribeConfiguration(LdClientContext context)
Parameters
Type Name Description
LdClientContext context

the context object that may provide relevant configuration details

Returns
Type Description
LdValue

a JSON value

MessageHandler(HttpMessageHandler)

Specifies a custom HTTP message handler implementation.

Declaration
public HttpConfigurationBuilder MessageHandler(HttpMessageHandler messageHandler)
Parameters
Type Name Description
System.Net.Http.HttpMessageHandler messageHandler

the message handler, or null to use the platform's default handler

Returns
Type Description
HttpConfigurationBuilder

the builder

Remarks

This is mainly useful for testing, to cause the SDK to use custom logic instead of actual HTTP requests, but can also be used to customize HTTP behavior on platforms where the default handler is not optimal. The default is the usual native HTTP handler for the current platform, if any (for instance, Xamarin.Android.Net.AndroidClientHandler), or else System.Net.Http.HttpClientHandler.

Proxy(IWebProxy)

Sets an HTTP proxy for making connections to LaunchDarkly.

Declaration
public HttpConfigurationBuilder Proxy(IWebProxy proxy)
Parameters
Type Name Description
System.Net.IWebProxy proxy

any implementation of System.Net.IWebProxy

Returns
Type Description
HttpConfigurationBuilder

the builder

Remarks

This is ignored if you have specified a custom message handler with MessageHandler(HttpMessageHandler), since proxy behavior is implemented by the message handler.

Note that this is not the same as the LaunchDarkly Relay Proxy, which would be set with RelayProxy(Uri).

Examples
    // Example of using an HTTP proxy with basic authentication

    var proxyUri = new Uri("http://my-proxy-host:8080");
    var proxy = new System.Net.WebProxy(proxyUri);
    var credentials = new System.Net.CredentialCache();
    credentials.Add(proxyUri, "Basic",
        new System.Net.NetworkCredential("username", "password"));
    proxy.Credentials = credentials;

    var config = Configuration.Builder("my-sdk-key")
        .Http(
            Components.HttpConfiguration().Proxy(proxy)
        )
        .Build();

ResponseStartTimeout(TimeSpan)

Sets the maximum amount of time to wait for the beginning of an HTTP response.

Declaration
public HttpConfigurationBuilder ResponseStartTimeout(TimeSpan responseStartTimeout)
Parameters
Type Name Description
System.TimeSpan responseStartTimeout

the timeout

Returns
Type Description
HttpConfigurationBuilder

the builder

Remarks

This limits how long the SDK will wait from the time it begins trying to make a network connection for an individual HTTP request to the time it starts receiving any data from the server. It is equivalent to the Timeout property in HttpClient.

It is not the same as the timeout parameter toInit(Configuration, Context, TimeSpan), which limits the time for initializing the SDK regardless of how many individual HTTP requests are done in that time.

See Also
ConnectTimeout(TimeSpan)

UseReport(Boolean)

Sets whether to use the HTTP REPORT method for feature flag requests.

Declaration
public HttpConfigurationBuilder UseReport(bool useReport)
Parameters
Type Name Description
System.Boolean useReport

true to enable the REPORT method

Returns
Type Description
HttpConfigurationBuilder

the builder

Remarks

By default, polling and streaming connections are made with the GET method, with the user data encoded into the request URI. Using REPORT allows the user data to be sent in the request body instead, which is somewhat more secure and efficient.

However, the REPORT method is not always supported: Android (in the versions tested so far) does not allow it, and some network gateways do not allow it. Therefore it is disabled in the SDK by default. You can enable it if you know your code will not be running on Android and not connecting through a gateway/proxy that disallows REPORT.

Wrapper(String, String)

For use by wrapper libraries to set an identifying name for the wrapper being used.

Declaration
public HttpConfigurationBuilder Wrapper(string wrapperName, string wrapperVersion)
Parameters
Type Name Description
System.String wrapperName

an identifying name for the wrapper library

System.String wrapperVersion

version string for the wrapper library

Returns
Type Description
HttpConfigurationBuilder

the builder

Remarks

This will be included in a header during requests to the LaunchDarkly servers to allow recording metrics on the usage of these wrapper libraries.

Implements

IDiagnosticDescription
In This Article
Back to top Generated by DocFX