Skip to content

Commit

Permalink
allow X-Super headers in CORS (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
dealloc authored Apr 30, 2024
1 parent 3e5f9b2 commit 6a29b3a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/Helldivers-2-API/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Helldivers.API;

/// <summary>
/// Contains constant strings used througout the API.
/// </summary>
public static class Constants
{
/// <summary>
/// The name of the header that identifies the client to the API.
/// </summary>
public static string CLIENT_HEADER_NAME = "X-Super-Client";

/// <summary>
/// The name of the header with developer contact information.
/// </summary>
public static string CONTACT_HEADER_NAME = "X-Super-Contact";
}
2 changes: 1 addition & 1 deletion src/Helldivers-2-API/Metrics/ClientMetric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!;

Expand Down
2 changes: 2 additions & 0 deletions src/Helldivers-2-API/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Helldivers.API;
using Helldivers.API.Configuration;
using Helldivers.API.Controllers;
using Helldivers.API.Controllers.V1;
Expand Down Expand Up @@ -79,6 +80,7 @@
options.AddDefaultPolicy(policy => policy
.AllowAnyOrigin()
.AllowAnyMethod()
.WithHeaders(Constants.CLIENT_HEADER_NAME, Constants.CONTACT_HEADER_NAME)
);
});

Expand Down

0 comments on commit 6a29b3a

Please sign in to comment.