Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SteamKit version as default user-agent #620

Merged
merged 2 commits into from
Feb 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using SteamKit2.Discovery;

namespace SteamKit2
Expand Down Expand Up @@ -107,6 +108,13 @@ public ISteamConfigurationBuilder WithWebAPIKey(string webApiKey)
return this;
}

static HttpClient DefaultHttpClientFactory() => new HttpClient();
static HttpClient DefaultHttpClientFactory()
{
var client = new HttpClient();

var assemblyVersion = typeof(SteamConfiguration).Assembly.GetName().Version.ToString(fieldCount: 3);
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("SteamKit", assemblyVersion));
return client;
}
}
}
4 changes: 4 additions & 0 deletions SteamKit2/Tests/SteamConfigurationFacts.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Http;
Expand Down Expand Up @@ -55,6 +56,9 @@ public void DefaultHttpClientFactory()
{
Assert.NotNull(client);
Assert.IsType<HttpClient>(client);

var steamKitAssemblyVersion = typeof( SteamClient ).Assembly.GetName().Version;
Assert.Equal("SteamKit/" + steamKitAssemblyVersion.ToString(fieldCount: 3), client.DefaultRequestHeaders.UserAgent.ToString());
}
}

Expand Down