Skip to content

Commit a6be170

Browse files
committed
send rid as header
1 parent ec827fe commit a6be170

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

Framework/Intersect.Framework.Core/AssetManagement/Updater.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@
33
using System.Diagnostics;
44
using System.Diagnostics.CodeAnalysis;
55
using System.Net;
6-
using System.Net.Http.Headers;
76
using System.Reflection;
87
using System.Runtime.InteropServices;
98
using System.Text;
10-
using Hardware.Info;
119
using Intersect.Core;
1210
using Intersect.Framework.SystemInformation;
1311
using Intersect.Web;
1412
using Microsoft.Extensions.Logging;
1513
using Newtonsoft.Json;
16-
using Serilog;
1714

1815
namespace Intersect.Framework.Core.AssetManagement;
1916

@@ -115,15 +112,6 @@ public UpdaterStatus TryGetManifest(out UpdateManifest? updateManifest, int reat
115112
try
116113
{
117114
using IntersectHttpClient httpClient = new(_baseUrl, _tokenResponse);
118-
httpClient.DefaultRequestHeaders.UserAgent.Clear();
119-
120-
var applicationContext = ApplicationContext.CurrentContext;
121-
var productName = applicationContext.Name.Replace(" ", "_");
122-
var productVersion = applicationContext.Version;
123-
var platformComment = new ProductInfoHeaderValue(comment: $"({PlatformInformation.RuntimeIdentifier})");
124-
ProductInfoHeaderValue productInfoHeaderValue = new(productName, productVersion);
125-
httpClient.DefaultRequestHeaders.UserAgent.Add(productInfoHeaderValue);
126-
httpClient.DefaultRequestHeaders.UserAgent.Add(platformComment);
127115

128116
HttpResponseMessage? responseMessage = default;
129117

@@ -240,7 +228,7 @@ public UpdaterStatus TryGetManifest(out UpdateManifest? updateManifest, int reat
240228
updateRequired = true;
241229
break;
242230
}
243-
231+
244232
var resolvedPath = ResolvePath(cachedFile.Path, _updateRootInfo.FullName);
245233
FileInfo resolvedInfo = new(resolvedPath);
246234
if (!resolvedInfo.Exists)

Framework/Intersect.Framework.Core/Web/IntersectHttpClient.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
using System.Net;
22
using System.Net.Http.Headers;
3-
using System.Security.Authentication;
43
using System.Security.Cryptography;
54
using System.Text;
65
using Intersect.Core;
76
using Intersect.Framework.Net;
7+
using Intersect.Framework.SystemInformation;
88
using Microsoft.Extensions.Logging;
99
using Newtonsoft.Json;
1010

1111
namespace Intersect.Web;
1212

1313
public partial class IntersectHttpClient : HttpClient
1414
{
15+
public const string HeaderIntersectRuntimeIdentifier = "X-Intersect-RuntimeIdentifier";
16+
1517
private static HttpClientHandler GetHttpClientHandler()
1618
{
1719
return new HttpClientHandler
@@ -46,6 +48,21 @@ public IntersectHttpClient(string serverUri, TokenResponse? tokenResponse = defa
4648

4749
_baseUri = new Uri(new Uri(serverUri), "/");
4850
_tokenResponse = tokenResponse;
51+
52+
53+
var applicationContext = ApplicationContext.CurrentContext;
54+
var productName = applicationContext.Name.Replace(" ", "_");
55+
var productVersion = applicationContext.Version;
56+
57+
var runtimeIdentifier = PlatformInformation.RuntimeIdentifier;
58+
var platformComment = new ProductInfoHeaderValue(comment: $"({runtimeIdentifier})");
59+
ProductInfoHeaderValue productInfoHeaderValue = new(productName, productVersion);
60+
DefaultRequestHeaders.UserAgent.Clear();
61+
DefaultRequestHeaders.UserAgent.Add(productInfoHeaderValue);
62+
DefaultRequestHeaders.UserAgent.Add(platformComment);
63+
64+
DefaultRequestHeaders.Add(HeaderIntersectRuntimeIdentifier, runtimeIdentifier);
65+
4966
}
5067

5168
public TokenResultType TryRequestToken(string username, string password, out TokenResponse? tokenResponse, bool hashed = false)

Intersect.Server/Web/IntersectController.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Security.Claims;
44
using Intersect.Security.Claims;
55
using Intersect.Server.Web.Types;
6+
using Intersect.Web;
67
using Microsoft.AspNetCore.Mvc;
78
using MyCSharp.HttpUserAgentParser.AspNetCore;
89
using IntersectUser = Intersect.Server.Database.PlayerData.User;
@@ -11,6 +12,21 @@ namespace Intersect.Server.Web;
1112

1213
public abstract class IntersectController : Controller
1314
{
15+
private string? _runtimeIdentifier;
16+
17+
public string? RuntimeIdentifier
18+
{
19+
get
20+
{
21+
if (string.IsNullOrWhiteSpace(_runtimeIdentifier))
22+
{
23+
_runtimeIdentifier = Request.Headers[IntersectHttpClient.HeaderIntersectRuntimeIdentifier];
24+
}
25+
26+
return _runtimeIdentifier;
27+
}
28+
}
29+
1430
private string? _userAgent;
1531
private string? _userAgentProductName;
1632
private string? _userAgentProductVersion;

0 commit comments

Comments
 (0)