Skip to content

Commit 50d2732

Browse files
authored
Add the ConnectTimeout property on the service client config for the .NET 8 target of the SDK. (#3820)
1 parent 3422632 commit 50d2732

File tree

6 files changed

+59
-0
lines changed

6 files changed

+59
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"core": {
3+
"updateMinimum": true,
4+
"type": "Patch",
5+
"changeLogMessages": [
6+
"Add the ConnectTimeout property on the service client config for the .NET 8 target of the SDK."
7+
]
8+
}
9+
}

sdk/src/Core/Amazon.Runtime/ClientConfig.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,31 @@ public TimeSpan? Timeout
832832
}
833833
}
834834

835+
#if NET8_0_OR_GREATER
836+
TimeSpan? _connectTimeout;
837+
838+
/// <summary>
839+
/// Gets and sets the connection timeout that will be set on the HttpClient used by the service client to make requests.
840+
/// The connection timeout is used control the wait time for the connection to be established to the service. The default
841+
/// connection timeout for the HttpClient is infinite waiting period.
842+
/// </summary>
843+
public TimeSpan? ConnectTimeout
844+
{
845+
get
846+
{
847+
if (!this._connectTimeout.HasValue)
848+
return null;
849+
850+
return this._connectTimeout.Value;
851+
}
852+
set
853+
{
854+
ValidateTimeout(value);
855+
this._connectTimeout = value;
856+
}
857+
}
858+
#endif
859+
835860
#if AWS_ASYNC_API
836861
/// <summary>
837862
/// Generates a <see cref="CancellationToken"/> based on the value

sdk/src/Core/Amazon.Runtime/IClientConfig.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,14 @@ public partial interface IClientConfig
245245
/// </remarks>
246246
TimeSpan? Timeout { get; }
247247

248+
#if NET8_0_OR_GREATER
249+
/// <summary>
250+
/// Gets the connection timeout that will be set on the HttpClient used by the service client to make requests.
251+
/// The connection timeout is used control the wait time for the connection to be established to the service.
252+
/// </summary>
253+
TimeSpan? ConnectTimeout { get; }
254+
#endif
255+
248256
/// <summary>
249257
/// Configures the endpoint calculation for a service to go to a dual stack (ipv6 enabled) endpoint
250258
/// for the configured region.

sdk/src/Core/Amazon.Runtime/Pipeline/HttpHandler/_netstandard/HttpRequestMessageFactory.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,16 @@ private static HttpClient CreateHttpClient(IClientConfig clientConfig)
245245
/// <returns></returns>
246246
private static HttpClient CreateManagedHttpClient(IClientConfig clientConfig)
247247
{
248+
#if NET8_0_OR_GREATER
249+
var httpMessageHandler = new SocketsHttpHandler();
250+
251+
if (clientConfig.ConnectTimeout.HasValue)
252+
{
253+
httpMessageHandler.ConnectTimeout = clientConfig.ConnectTimeout.Value;
254+
}
255+
#else
248256
var httpMessageHandler = new HttpClientHandler();
257+
#endif
249258

250259
if (clientConfig.MaxConnectionsPerServer.HasValue)
251260
httpMessageHandler.MaxConnectionsPerServer = clientConfig.MaxConnectionsPerServer.Value;

sdk/src/Core/Amazon.Runtime/_netstandard/ClientConfig.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ internal static string CreateConfigUniqueString(IClientConfig clientConfig)
168168
if (clientConfig.MaxConnectionsPerServer.HasValue)
169169
uniqueString = string.Concat(uniqueString, "MaxConnectionsPerServer:", clientConfig.MaxConnectionsPerServer.Value.ToString());
170170

171+
#if NET8_0_OR_GREATER
172+
if (clientConfig.ConnectTimeout.HasValue)
173+
uniqueString = string.Concat(uniqueString, "ConnectTimeout:", clientConfig.ConnectTimeout.Value.ToString());
174+
#endif
175+
171176
return uniqueString;
172177
}
173178

sdk/test/NetStandard/UnitTests/ClientConfigTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public class ClientConfigTests
3838
"DisableLogging",
3939
"ProxyCredentials",
4040
"Timeout",
41+
#if NET8_0_OR_GREATER
42+
"ConnectTimeout",
43+
#endif
4144
"UseDualstackEndpoint",
4245
"UseFIPSEndpoint",
4346
"ProxyHost",

0 commit comments

Comments
 (0)