Skip to content

Commit

Permalink
Merge pull request #1208 from ge-digital-firestorm/Fix1178
Browse files Browse the repository at this point in the history
Fix issue where "Spring:Cloud:Config:Timeout" configuration property isn't respected
  • Loading branch information
TimHess authored Oct 25, 2023
2 parents a662cc1 + 10cb626 commit 55211fe
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/Common/src/Common.Http/HttpClientHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ public static HttpClient GetHttpClient(bool validateCertificates, HttpClientHand
}
}

client.Timeout = TimeSpan.FromMilliseconds(timeoutMillis);
if (timeoutMillis > 0)
{
client.Timeout = TimeSpan.FromMilliseconds(timeoutMillis);
}

client.DefaultRequestHeaders.UserAgent.ParseAdd(SteeltoeUserAgent);
return client;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ internal void Initialize(ConfigServerClientSettings settings, IConfiguration con
}

_settings = settings;
_httpClient = httpClient ?? GetHttpClient(_settings);

OnSettingsChanged();

_httpClient = httpClient ?? GetHttpClient(_settings);
}

private void OnSettingsChanged()
Expand Down Expand Up @@ -960,7 +960,7 @@ protected internal bool IsDiscoveryFirstEnabled()
}

/// <summary>
/// Creates an appropriatly configured HttpClient that will be used in communicating with the
/// Creates an appropriately configured HttpClient that will be used in communicating with the
/// Spring Cloud Configuration Server
/// </summary>
/// <param name="settings">the settings used in configuring the HttpClient</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ public void SourceConstructor_WithDefaults_InitializesWithDefaultSettings()
TestHelper.VerifyDefaults(provider.Settings);
}

[Fact]
public void SourceConstructor_WithTimeoutConfigured_InitializesHttpClientWithConfiguredTimeout()
{
IConfiguration configuration = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>
{
{ "spring:cloud:config:timeout", "30000" }
})
.Build();
var source = new ConfigServerConfigurationSource(configuration);
var provider = new TestConfigServerConfigurationProvider(source);

Assert.Equal(TimeSpan.FromMilliseconds(30000), provider.TheConfiguredClient.Timeout);
}

[Fact]
public void SourceConstructor_WithDefaults_ThrowsIfHttpClientNull()
{
Expand Down Expand Up @@ -1160,6 +1175,11 @@ public TestConfigServerConfigurationProvider(ConfigServerClientSettings settings
{
}

public TestConfigServerConfigurationProvider(ConfigServerConfigurationSource source)
: base(source)
{
}

public HttpClient TheConfiguredClient => _httpClient;
}

Expand Down

0 comments on commit 55211fe

Please sign in to comment.