mirror of
https://github.com/sbrl/PolyFeed.git
synced 2024-11-14 05:13:00 +00:00
Add user agent string
This commit is contained in:
parent
205c7112c2
commit
a060a10b55
3 changed files with 39 additions and 1 deletions
|
@ -30,7 +30,10 @@ namespace PolyFeed
|
|||
|
||||
public async Task AddSource(FeedSource source) {
|
||||
await Console.Error.WriteLineAsync("[Builder] Downloading content");
|
||||
WebResponse response = await WebRequest.Create(source.Feed.Url).GetResponseAsync();
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(source.Feed.Url);
|
||||
|
||||
request.UserAgent = UserAgentHelper.UserAgent;
|
||||
WebResponse response = await request.GetResponseAsync();
|
||||
|
||||
await Console.Error.WriteLineAsync("[Builder] Generating feed header");
|
||||
|
||||
|
|
34
PolyFeed/Helpers/UserAgentHelper.cs
Normal file
34
PolyFeed/Helpers/UserAgentHelper.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace PolyFeed.Helpers
|
||||
{
|
||||
public static class UserAgentHelper
|
||||
{
|
||||
public static string UserAgent {
|
||||
get {
|
||||
return $"PolyFeed/{version} ({os_name} {cpu_arch}; +https://github.com/sbrl/PolyFeed) .NET-CLR/{clr_version} {mono_info}";
|
||||
}
|
||||
}
|
||||
|
||||
private static string version => Program.GetProgramVersion();
|
||||
private static string os_name => Environment.OSVersion.Platform.ToString().Replace("Unix", "Linux");
|
||||
private static string cpu_arch => System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture.ToString();
|
||||
|
||||
private static string clr_version => Environment.Version.ToString();
|
||||
|
||||
private static string mono_info {
|
||||
get {
|
||||
Type type = Type.GetType("Mono.Runtime");
|
||||
if (type == null)
|
||||
return string.Empty;
|
||||
|
||||
MethodInfo displayName = type.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
|
||||
if (displayName != null)
|
||||
return $"Mono/{(string)displayName.Invoke(null, null)}";
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -149,6 +149,7 @@
|
|||
<Compile Include="ReferenceSubstitutor.cs" />
|
||||
<Compile Include="SnakeCasePropertySelector.cs" />
|
||||
<Compile Include="Helpers\HtmlHelpers.cs" />
|
||||
<Compile Include="Helpers\UserAgentHelper.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
|
Loading…
Reference in a new issue