Class HttpConfigurationBuilder
Contains methods for configuring the SDK's networking behavior.
Implements
Inherited Members
Namespace: LaunchDarkly.Sdk.Client.Integrations
Assembly: LaunchDarkly.ClientSdk.dll
Syntax
public sealed class HttpConfigurationBuilder : 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
View SourceHttpConfigurationBuilder()
Declaration
public HttpConfigurationBuilder()
Fields
| Edit this page View SourceDefaultConnectTimeout
The default value for ConnectTimeout(TimeSpan): 10 seconds.
Declaration
public static readonly TimeSpan DefaultConnectTimeout
Field Value
Type | Description |
---|---|
TimeSpan |
DefaultResponseStartTimeout
The default value for ResponseStartTimeout(TimeSpan): 10 seconds.
Declaration
public static readonly TimeSpan DefaultResponseStartTimeout
Field Value
Type | Description |
---|---|
TimeSpan |
Methods
| Edit this page View SourceConnectTimeout(TimeSpan)
Sets the network connection timeout.
Declaration
public HttpConfigurationBuilder ConnectTimeout(TimeSpan connectTimeout)
Parameters
Type | Name | Description |
---|---|---|
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 MAUI Android, but not in MAUI 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 HttpMessageHandler,
the ConnectTimeout(TimeSpan) here will be ignored.
See Also
| Edit this page View SourceCreateHttpConfiguration(string, ApplicationInfo?)
Called internally by the SDK to create an implementation instance. Applications do not need to call this method.
Declaration
public HttpConfiguration CreateHttpConfiguration(string authKey, ApplicationInfo? applicationInfo)
Parameters
Type | Name | Description |
---|---|---|
string | authKey | Key for authenticating with LD service |
ApplicationInfo? | applicationInfo | Application Info for this application environment |
Returns
Type | Description |
---|---|
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 |
---|---|---|
string | name | the header name |
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 |
---|---|---|
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, else HttpClientHandler.
Proxy(IWebProxy)
Sets an HTTP proxy for making connections to LaunchDarkly.
Declaration
public HttpConfigurationBuilder Proxy(IWebProxy proxy)
Parameters
Type | Name | Description |
---|---|---|
IWebProxy | proxy | any implementation of |
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();
|
Edit this page
View Source
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 |
---|---|---|
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
| Edit this page View SourceUseReport(bool)
Sets whether to use the HTTP REPORT
method for feature flag requests.
Declaration
public HttpConfigurationBuilder UseReport(bool useReport)
Parameters
Type | Name | Description |
---|---|---|
bool | 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 |
---|---|---|
string | wrapperName | an identifying name for the wrapper library |
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.