Skip to content

Commit efb2bcb

Browse files
committed
Tidy user-agent strings passed to servers from EDDI.
1 parent e591860 commit efb2bcb

4 files changed

Lines changed: 17 additions & 2 deletions

File tree

CompanionAppService/CompanionAppService.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Linq;
99
using System.Net;
1010
using System.Net.Http;
11+
using System.Net.Http.Headers;
1112
using System.Runtime.CompilerServices;
1213
using System.Security.Cryptography;
1314
using System.Text;
@@ -29,7 +30,7 @@ public class CompanionAppService : IDisposable, INotifyPropertyChanged
2930
private static readonly string AUDIENCE = "audience=all";
3031
private static readonly string SCOPE = "scope=capi auth";
3132

32-
private static readonly HttpClient httpClient = new HttpClient();
33+
private readonly HttpClient httpClient;
3334
private readonly CustomURLResponder URLResponder;
3435
private string verifier;
3536
private string authSessionID;
@@ -110,6 +111,11 @@ private CompanionAppService ()
110111
Credentials = CompanionAppCredentials.Load();
111112
var appPath = System.Reflection.Assembly.GetEntryAssembly()?.Location;
112113
void logger(string message) => Logging.Error(message);
114+
115+
httpClient = new HttpClient();
116+
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd( $"{Constants.EDDI_NAME}/{Constants.EDDI_VERSION}" );
117+
httpClient.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue( "application/json" ) );
118+
113119
URLResponder = new CustomURLResponder(Constants.EDDI_URL_PROTOCOL, handleCallbackUrl, logger, appPath);
114120
clientID = ClientId.ID;
115121
if (clientID == null)

EDDNResponder/Sender/EDDN_Sender.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ static EDDNSender ()
3535
{
3636
BaseAddress = new Uri(baseUrl)
3737
};
38+
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd( $"{Constants.EDDI_NAME}/{Constants.EDDI_VERSION}" );
39+
httpClient.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue( "application/json" ) );
3840
}
3941

4042
// Schemas identified as invalid by the server

EddiCore/Upgrader/EddiUpgrader.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Diagnostics;
66
using System.IO;
77
using System.Net.Http;
8+
using System.Net.Http.Headers;
89
using System.Reflection;
910
using System.Text.RegularExpressions;
1011
using System.Threading.Tasks;
@@ -38,7 +39,8 @@ public static async Task CheckUpgrade ()
3839
using ( var client = new HttpClient() )
3940
{
4041
// Set the User-Agent header as required by GitHub API
41-
client.DefaultRequestHeaders.Add( "User-Agent", "EDDI-Upgrader" );
42+
client.DefaultRequestHeaders.UserAgent.ParseAdd( $"{Constants.EDDI_NAME}/{Constants.EDDI_VERSION} - Upgrader" );
43+
client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue( "application/json" ) );
4244

4345
string response = null;
4446

EddiSpanshService/SpanshService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Net;
44
using System.Net.Http;
5+
using System.Net.Http.Headers;
56
using System.Threading;
67
using System.Threading.Tasks;
78
using Utilities;
@@ -43,6 +44,10 @@ public SpanshHttpClient (string baseUrl)
4344
BaseAddress = new Uri( baseUrl ),
4445
Timeout = TimeSpan.FromMilliseconds( DefaultTimeoutMilliseconds )
4546
};
47+
client.DefaultRequestHeaders.UserAgent
48+
.ParseAdd( $"{Constants.EDDI_NAME}/{Constants.EDDI_VERSION}" );
49+
client.DefaultRequestHeaders.Accept
50+
.Add( new MediaTypeWithQualityHeaderValue( "application/json" ) );
4651
}
4752

4853
public async Task<HttpResponseMessage> GetAsync ( string requestUri, CancellationToken cancellationToken )

0 commit comments

Comments
 (0)