Skip to content

Commit 881caee

Browse files
Update header value
1 parent 9f215f2 commit 881caee

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

IntelliTect.Multitool.Tests/Extensions/HttpExtensionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ static HttpExtensionsTests()
1717
[InlineData("https://api.github.com/meta", true)]
1818
public async void ValidateUri_CheckUrl_SuccessIsAsExpected(string urlUnderTest, bool expected)
1919
{
20-
Assert.Equal(expected, await HttpClient.ValidateUri(new Uri(urlUnderTest)));
20+
Assert.Equal(expected, await HttpClient.ValidateUri(new Uri(urlUnderTest), "IntelliTect.Multitool.Testing-" + Guid.NewGuid().ToString()[..10]));
2121
}
2222
}

IntelliTect.Multitool/Extensions/HttpExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ public static class HttpExtensions
1010
/// </summary>
1111
/// <param name="client">The HttpClient to make the request</param>
1212
/// <param name="uri">The Uri to validate</param>
13+
/// <param name="headerValue">A string for what will be passed in the header of the validation.</param>
1314
/// <returns>The result of the call</returns>
14-
public static async Task<bool> ValidateUri(this HttpClient client, Uri uri)
15+
public static async Task<bool> ValidateUri(this HttpClient client, Uri uri, string headerValue = "IntelliTect.Multitool")
1516
{
1617
try
1718
{
1819
// Clear then add a user-agent header in case the API requires one (such as github.com or stackoverflow.com)
1920
// https://docs.github.com/rest/overview/resources-in-the-rest-api#user-agent-required
2021
client.DefaultRequestHeaders.Clear();
21-
client.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue(new System.Net.Http.Headers.ProductHeaderValue("IntelliTect.Multitool")));
22+
client.DefaultRequestHeaders.UserAgent.Add(new System.Net.Http.Headers.ProductInfoHeaderValue(new System.Net.Http.Headers.ProductHeaderValue(headerValue)));
2223

2324
HttpResponseMessage result = await client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead);
2425
result.EnsureSuccessStatusCode();

0 commit comments

Comments
 (0)