Skip to content

Commit 36c4c7a

Browse files
committed
incorporate rid in manifest request to get binaries
1 parent 4c04c77 commit 36c4c7a

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
using System.Diagnostics;
44
using System.Diagnostics.CodeAnalysis;
55
using System.Net;
6+
using System.Net.Http.Headers;
67
using System.Reflection;
78
using System.Runtime.InteropServices;
89
using System.Text;
10+
using Hardware.Info;
911
using Intersect.Core;
12+
using Intersect.Framework.SystemInformation;
1013
using Intersect.Web;
1114
using Microsoft.Extensions.Logging;
1215
using Newtonsoft.Json;
@@ -120,6 +123,15 @@ public UpdaterStatus TryGetManifest(out UpdateManifest? updateManifest, int reat
120123
try
121124
{
122125
using IntersectHttpClient httpClient = new(_baseUrl, _tokenResponse);
126+
httpClient.DefaultRequestHeaders.UserAgent.Clear();
127+
128+
var applicationContext = ApplicationContext.CurrentContext;
129+
var productName = applicationContext.Name.Replace(" ", "_");
130+
var productVersion = applicationContext.Version;
131+
var platformComment = new ProductInfoHeaderValue(comment: $"({PlatformInformation.RuntimeIdentifier})");
132+
ProductInfoHeaderValue productInfoHeaderValue = new(productName, productVersion);
133+
httpClient.DefaultRequestHeaders.UserAgent.Add(productInfoHeaderValue);
134+
httpClient.DefaultRequestHeaders.UserAgent.Add(platformComment);
123135

124136
HttpResponseMessage? responseMessage = default;
125137

@@ -129,9 +141,24 @@ public UpdaterStatus TryGetManifest(out UpdateManifest? updateManifest, int reat
129141
{
130142
try
131143
{
144+
KeyValuePair<string, string>[] queryParameters =
145+
[
146+
new("token", Environment.TickCount.ToString()),
147+
new("rid", PlatformInformation.RuntimeIdentifier),
148+
];
149+
UriBuilder requestUriBuilder = new(_manifestUrl ?? throw new InvalidOperationException())
150+
{
151+
Query = string.Join(
152+
"&",
153+
queryParameters.Select(
154+
p => string.Join('=', Uri.EscapeDataString(p.Key), Uri.EscapeDataString(p.Value))
155+
)
156+
),
157+
};
158+
var requestUri = requestUriBuilder.Uri;
132159
using HttpRequestMessage requestMessage = new(
133160
HttpMethod.Get,
134-
$"{_manifestUrl}?token={Environment.TickCount}"
161+
requestUri
135162
);
136163

137164
ApplicationContext.CurrentContext.Logger.LogInformation(

Framework/Intersect.Framework.Core/Core/IApplicationContext.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ bool IsDebug
7676
/// </summary>
7777
List<IApplicationService> Services { get; }
7878

79+
/// <summary>
80+
/// The version string used in protocol communication.
81+
/// </summary>
82+
string Version => GetType().Assembly.GetMetadataVersion();
83+
7984
/// <summary>
8085
/// The human-friendly version string.
8186
/// </summary>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public TokenResultType TryRequestToken(string refreshToken, out TokenResponse? t
149149
var tokenRequestBody = JsonConvert.SerializeObject(objectTokenRequestBody);
150150
requestMessage.Content = new StringContent(tokenRequestBody, MediaTypeHeaderValue.Parse("application/json"));
151151

152-
var responseMessage = Send(requestMessage);
152+
var responseMessage = base.Send(requestMessage);
153153
if (responseMessage.StatusCode != HttpStatusCode.OK)
154154
{
155155
ApplicationContext.Context.Value?.Logger.LogError(

0 commit comments

Comments
 (0)