Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Core/Resolvers/SqlMutationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,12 @@ await queryExecutor.ExecuteQueryAsync(
case EntityActionOperation.Insert:

HttpContext httpContext = GetHttpContext();
// Use scheme/host from X-Forwarded-* headers if present, else fallback to request values
string scheme = SqlPaginationUtil.ResolveRequestScheme(httpContext.Request);
string host = SqlPaginationUtil.ResolveRequestHost(httpContext.Request);
string locationHeaderURL = UriHelper.BuildAbsolute(
scheme: httpContext.Request.Scheme,
host: httpContext.Request.Host,
scheme: scheme,
host: new HostString(host),
pathBase: GetBaseRouteFromConfig(_runtimeConfigProvider.GetConfig()),
path: httpContext.Request.Path);

Expand Down
8 changes: 4 additions & 4 deletions src/Core/Resolvers/SqlPaginationUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ public static string FormatQueryString(NameValueCollection? queryStringParameter
/// <param name="req">The HTTP request.</param>
/// <returns>The scheme string ("http" or "https").</returns>
/// <exception cref="DataApiBuilderException">Thrown when client explicitly sets an invalid scheme.</exception>
private static string ResolveRequestScheme(HttpRequest req)
internal static string ResolveRequestScheme(HttpRequest req)
{
string? rawScheme = req.Headers["X-Forwarded-Proto"].FirstOrDefault();
string? normalized = rawScheme?.Trim().ToLowerInvariant();
Expand All @@ -780,7 +780,7 @@ private static string ResolveRequestScheme(HttpRequest req)
/// <param name="req">The HTTP request.</param>
/// <returns>The host string.</returns>
/// <exception cref="DataApiBuilderException">Thrown when client explicitly sets an invalid host.</exception>
private static string ResolveRequestHost(HttpRequest req)
internal static string ResolveRequestHost(HttpRequest req)
{
string? rawHost = req.Headers["X-Forwarded-Host"].FirstOrDefault();
string? trimmed = rawHost?.Trim();
Expand All @@ -803,7 +803,7 @@ private static string ResolveRequestHost(HttpRequest req)
/// </summary>
/// <param name="scheme">Scheme, e.g., "http" or "https".</param>
/// <returns>True if valid, otherwise false.</returns>
private static bool IsValidScheme(string? scheme)
internal static bool IsValidScheme(string? scheme)
{
return scheme is "http" or "https";
}
Expand All @@ -813,7 +813,7 @@ private static bool IsValidScheme(string? scheme)
/// </summary>
/// <param name="host">The host name (with optional port).</param>
/// <returns>True if valid, otherwise false.</returns>
private static bool IsValidHost(string? host)
internal static bool IsValidHost(string? host)
{
if (string.IsNullOrWhiteSpace(host))
{
Expand Down
7 changes: 5 additions & 2 deletions src/Core/Resolvers/SqlResponseHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,12 @@ HttpContext httpContext
// The third part is the computed primary key route.
if (operationType is EntityActionOperation.Insert && !string.IsNullOrEmpty(primaryKeyRoute))
{
// Use scheme/host from X-Forwarded-* headers if present, else fallback to request values
string scheme = SqlPaginationUtil.ResolveRequestScheme(httpContext.Request);
string host = SqlPaginationUtil.ResolveRequestHost(httpContext.Request);
locationHeaderURL = UriHelper.BuildAbsolute(
scheme: httpContext.Request.Scheme,
host: httpContext.Request.Host,
scheme: scheme,
host: new HostString(host),
pathBase: baseRoute,
path: httpContext.Request.Path);

Expand Down