Skip to content

Commit

Permalink
Merge pull request Azure#1012 from abhivijay96/master
Browse files Browse the repository at this point in the history
 ServiceClient that allows setting the UserAgent string
  • Loading branch information
tbombach committed May 26, 2016
2 parents 73987f0 + ca2b687 commit ab5315f
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,47 @@ protected void InitializeHttpClient(HttpClientHandler httpClientHandler, params
GetClientVersion()));
}

/// <summary>
/// Sets the product name to be used in the user agent header when making requests
/// </summary>
/// <param name="productName">Name of the product to be used in the user agent</param>
public bool SetUserAgent(string productName)
{
if (!_disposed && HttpClient != null)
{
// Clear the old user agent
HttpClient.DefaultRequestHeaders.UserAgent.Clear();
HttpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(productName, GetClientVersion()));

// Returns true if the user agent was set
return true;
}

// Returns false if the HttpClient was disposed before invoking the method
return false;
}

/// <summary>
/// Sets the product name and version to be used in the user agent header when making requests
/// </summary>
/// <param name="productName">Name of the product to be used in the user agent</param>
/// <param name="version">Version of the product to be used in the user agent</param>
public bool SetUserAgent(string productName, string version)
{
if (!_disposed && HttpClient != null)
{
// Clear the old user agent
HttpClient.DefaultRequestHeaders.UserAgent.Clear();
HttpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(productName, version));

// Returns true if the user agent was set
return true;
}

// Returns false if the HttpClient was disposed before invoking the method
return false;
}

/// <summary>
/// Gets the AssemblyInformationalVersion if available
/// if not it gets the AssemblyFileVerion
Expand Down

0 comments on commit ab5315f

Please sign in to comment.