Skip to content

Commit 2a16d2b

Browse files
authored
Handle trailing slash in /api request (#5129)
1 parent 83be2ea commit 2a16d2b

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

src/ServiceControl.Audit/Infrastructure/WebApi/RootController.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@ public RootController(Settings settings)
1818
[HttpGet]
1919
public OkObjectResult Urls()
2020
{
21-
var baseUrl = Request.GetDisplayUrl() + "/";
21+
var baseUrl = Request.GetDisplayUrl();
22+
23+
if (!baseUrl.EndsWith('/'))
24+
{
25+
baseUrl += "/";
26+
}
27+
2228
var model = new RootUrls
2329
{
2430
KnownEndpointsUrl = "/endpoints/known", // relative URI to allow proxying
25-
MessageSearchUrl =
26-
baseUrl + "messages/search/{keyword}/{?page,per_page,direction,sort}",
27-
EndpointsMessageSearchUrl =
28-
baseUrl +
29-
"endpoints/{name}/messages/search/{keyword}/{?page,per_page,direction,sort}",
30-
EndpointsMessagesUrl =
31-
baseUrl + "endpoints/{name}/messages/{?page,per_page,direction,sort}",
31+
MessageSearchUrl = baseUrl + "messages/search/{keyword}/{?page,per_page,direction,sort}",
32+
EndpointsMessageSearchUrl = baseUrl + "endpoints/{name}/messages/search/{keyword}/{?page,per_page,direction,sort}",
33+
EndpointsMessagesUrl = baseUrl + "endpoints/{name}/messages/{?page,per_page,direction,sort}",
3234
AuditCountUrl = baseUrl + "endpoints/{name}/audit-count",
3335
Name = SettingsReader.Read(Settings.SettingsRootNamespace, "Name", "ServiceControl.Audit"),
3436
Description = SettingsReader.Read(Settings.SettingsRootNamespace, "Description", "The audit backend for the Particular Service Platform"),

src/ServiceControl/Infrastructure/Api/ConfigurationApi.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,25 @@
1414
using ServiceControl.Api;
1515
using ServiceControl.Api.Contracts;
1616

17-
class ConfigurationApi(ActiveLicense license,
18-
Settings settings,
19-
IHttpClientFactory httpClientFactory, MassTransitConnectorHeartbeatStatus connectorHeartbeatStatus) : IConfigurationApi
17+
class ConfigurationApi(ActiveLicense license, Settings settings, IHttpClientFactory httpClientFactory, MassTransitConnectorHeartbeatStatus connectorHeartbeatStatus) : IConfigurationApi
2018
{
2119
public Task<RootUrls> GetUrls(string baseUrl, CancellationToken cancellationToken)
2220
{
21+
if (!baseUrl.EndsWith('/'))
22+
{
23+
baseUrl += "/";
24+
}
25+
2326
var model = new RootUrls
2427
{
2528
EndpointsUrl = baseUrl + "endpoints",
2629
KnownEndpointsUrl = "/endpoints/known", // relative URI to allow proxying
2730
SagasUrl = baseUrl + "sagas",
2831
ErrorsUrl = baseUrl + "errors/{?page,per_page,direction,sort}",
2932
EndpointsErrorUrl = baseUrl + "endpoints/{name}/errors/{?page,per_page,direction,sort}",
30-
MessageSearchUrl =
31-
baseUrl + "messages/search/{keyword}/{?page,per_page,direction,sort}",
32-
EndpointsMessageSearchUrl =
33-
baseUrl +
34-
"endpoints/{name}/messages/search/{keyword}/{?page,per_page,direction,sort}",
35-
EndpointsMessagesUrl =
36-
baseUrl + "endpoints/{name}/messages/{?page,per_page,direction,sort}",
33+
MessageSearchUrl = baseUrl + "messages/search/{keyword}/{?page,per_page,direction,sort}",
34+
EndpointsMessageSearchUrl = baseUrl + "endpoints/{name}/messages/search/{keyword}/{?page,per_page,direction,sort}",
35+
EndpointsMessagesUrl = baseUrl + "endpoints/{name}/messages/{?page,per_page,direction,sort}",
3736
AuditCountUrl = baseUrl + "endpoints/{name}/audit-count",
3837
Name = SettingsReader.Read(Settings.SettingsRootNamespace, "Name", "ServiceControl"),
3938
Description = SettingsReader.Read(Settings.SettingsRootNamespace, "Description", "The management backend for the Particular Service Platform"),

src/ServiceControl/Infrastructure/WebApi/RootController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class RootController(IConfigurationApi configurationApi) : ControllerBase
1313
{
1414
[Route("")]
1515
[HttpGet]
16-
public Task<RootUrls> Urls() => configurationApi.GetUrls(Request.GetDisplayUrl() + "/", default);
16+
public Task<RootUrls> Urls() => configurationApi.GetUrls(Request.GetDisplayUrl(), default);
1717

1818
[Route("instance-info")]
1919
[Route("configuration")]

0 commit comments

Comments
 (0)