diff --git a/src/SdkCommon/ClientRuntime/ClientRuntime.Tests/ServiceClientTests.cs b/src/SdkCommon/ClientRuntime/ClientRuntime.Tests/ServiceClientTests.cs
index 358a0b61f0a89..97a5af01229fb 100644
--- a/src/SdkCommon/ClientRuntime/ClientRuntime.Tests/ServiceClientTests.cs
+++ b/src/SdkCommon/ClientRuntime/ClientRuntime.Tests/ServiceClientTests.cs
@@ -24,6 +24,23 @@ public void ClientAddHandlerToPipelineAddsHandler()
Assert.Equal(HttpStatusCode.InternalServerError, result2.StatusCode);
}
+ [Fact]
+ public void ClientDefaultHeaderValuesTest()
+ {
+ var fakeClient = new FakeServiceClient(new HttpClientHandler(), new BadResponseDelegatingHandler());
+ var arr = fakeClient.HttpClient.DefaultRequestHeaders.UserAgent.Where(pihv => String.IsNullOrWhiteSpace(pihv.Product.Version)).ToArray();
+ Assert.Empty(arr);
+ }
+
+ [Fact]
+ public void ClientEmptyProductHeaderValuesTest()
+ {
+ var fakeClient = new FakeServiceClient(new HttpClientHandler(), new BadResponseDelegatingHandler());
+ fakeClient.SetUserAgent("MySpecialHeader", string.Empty);
+ var arr = fakeClient.HttpClient.DefaultRequestHeaders.UserAgent.Where(pihv => (pihv.Product.Name == "MySpecialHeader")).ToArray();
+ Assert.Empty(arr);
+ }
+
[Fact]
public void ClientAddHandlersToPipelineAddSingleHandler()
{
diff --git a/src/SdkCommon/ClientRuntime/ClientRuntime/Microsoft.Rest.ClientRuntime.csproj b/src/SdkCommon/ClientRuntime/ClientRuntime/Microsoft.Rest.ClientRuntime.csproj
index 36de3a67d49da..534e7283ef61b 100644
--- a/src/SdkCommon/ClientRuntime/ClientRuntime/Microsoft.Rest.ClientRuntime.csproj
+++ b/src/SdkCommon/ClientRuntime/ClientRuntime/Microsoft.Rest.ClientRuntime.csproj
@@ -4,12 +4,12 @@
Infrastructure for error handling, tracing, and HttpClient pipeline configuration. Required by client libraries generated using AutoRest.
Microsoft.Rest.ClientRuntime
Client Runtime Library for Microsoft AutoRest Generated Clients
- 2.3.13
+ 2.3.14
Microsoft.Rest.ClientRuntime
Microsoft AutoRest ClientRuntime $(NugetCommonTags) $(NugetCommonProfileTags)
diff --git a/src/SdkCommon/ClientRuntime/ClientRuntime/ServiceClient.cs b/src/SdkCommon/ClientRuntime/ClientRuntime/ServiceClient.cs
index 08272679c8c6e..6bacc72174ffd 100644
--- a/src/SdkCommon/ClientRuntime/ClientRuntime/ServiceClient.cs
+++ b/src/SdkCommon/ClientRuntime/ClientRuntime/ServiceClient.cs
@@ -484,7 +484,7 @@ public bool SetUserAgent(string productName)
/// Version of the product to be used in the user agent
public bool SetUserAgent(string productName, string version)
{
- if (!_disposed && HttpClient != null)
+ if (!_disposed && HttpClient != null && !string.IsNullOrWhiteSpace(version))
{
string cleanedProductName = CleanUserAgentInfoEntry(productName);
AddUserAgentEntry(new ProductInfoHeaderValue(cleanedProductName, version));
@@ -527,7 +527,8 @@ private void MergeUserAgentInfo(List defaultUserAgentInf
// If you want to log ProductName in userAgent, it has to be without spaces
foreach(ProductInfoHeaderValue piHv in defaultUserAgentInfoList)
{
- if(!HttpClient.DefaultRequestHeaders.UserAgent.Any((hv) => hv.Product.Name.Equals(piHv.Product.Name, StringComparison.OrdinalIgnoreCase)))
+ if(!HttpClient.DefaultRequestHeaders.UserAgent.Any((hv) => hv.Product.Name.Equals(piHv.Product.Name, StringComparison.OrdinalIgnoreCase))
+ && !string.IsNullOrWhiteSpace(piHv.Product.Version))
{
HttpClient.DefaultRequestHeaders.UserAgent.Add(piHv);
}