diff --git a/src/Helldivers-2-API/Constants.cs b/src/Helldivers-2-API/Constants.cs new file mode 100644 index 0000000..5c35b50 --- /dev/null +++ b/src/Helldivers-2-API/Constants.cs @@ -0,0 +1,17 @@ +namespace Helldivers.API; + +/// +/// Contains constant strings used througout the API. +/// +public static class Constants +{ + /// + /// The name of the header that identifies the client to the API. + /// + public static string CLIENT_HEADER_NAME = "X-Super-Client"; + + /// + /// The name of the header with developer contact information. + /// + public static string CONTACT_HEADER_NAME = "X-Super-Contact"; +} diff --git a/src/Helldivers-2-API/Metrics/ClientMetric.cs b/src/Helldivers-2-API/Metrics/ClientMetric.cs index b4096b6..00883da 100644 --- a/src/Helldivers-2-API/Metrics/ClientMetric.cs +++ b/src/Helldivers-2-API/Metrics/ClientMetric.cs @@ -30,7 +30,7 @@ public static string GetClientName(HttpContext context) return name; // If the client sends `X-Super-Client` we use that name - if (context.Request.Headers.TryGetValue("X-Super-Client", out var superClient)) + if (context.Request.Headers.TryGetValue(Constants.CLIENT_HEADER_NAME, out var superClient)) if (string.IsNullOrWhiteSpace(superClient) is false) return superClient!; diff --git a/src/Helldivers-2-API/Program.cs b/src/Helldivers-2-API/Program.cs index da807e5..b42ed4d 100644 --- a/src/Helldivers-2-API/Program.cs +++ b/src/Helldivers-2-API/Program.cs @@ -1,3 +1,4 @@ +using Helldivers.API; using Helldivers.API.Configuration; using Helldivers.API.Controllers; using Helldivers.API.Controllers.V1; @@ -79,6 +80,7 @@ options.AddDefaultPolicy(policy => policy .AllowAnyOrigin() .AllowAnyMethod() + .WithHeaders(Constants.CLIENT_HEADER_NAME, Constants.CONTACT_HEADER_NAME) ); });