Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Raynald Messié <redbird_project@yahoo.fr>
  • Loading branch information
2 people authored and raman-m committed Apr 5, 2024
1 parent 452852b commit 7ae47a8
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public async Task Invoke(HttpContext httpContext)
httpContext.Items.UpsertErrors(response.Errors);
return;
}


var dsPath = response.Data.Value;
if (dsPath.EndsWith(Slash) && !upstreamPath.EndsWith(Slash))
{
{
dsPath = dsPath.TrimEnd(Slash);
response = new OkResponse<DownstreamPath>(new DownstreamPath(dsPath));
}
Expand All @@ -76,8 +76,8 @@ public async Task Invoke(HttpContext httpContext)
{
downstreamRequest.AbsolutePath = GetPath(dsPath);
var newQuery = GetQueryString(dsPath);
downstreamRequest.Query = string.IsNullOrEmpty(downstreamRequest.Query)
? newQuery
downstreamRequest.Query = string.IsNullOrEmpty(downstreamRequest.Query)
? newQuery
: MergeQueryStringsWithoutDuplicateValues(downstreamRequest.Query, newQuery, placeholders);
}
else
Expand All @@ -98,13 +98,15 @@ private static string MergeQueryStringsWithoutDuplicateValues(string queryString
newQueryString = newQueryString.Replace(QuestionMark, Ampersand);
var queries = HttpUtility.ParseQueryString(queryString);
var newQueries = HttpUtility.ParseQueryString(newQueryString);


// Remove old replaced query parameters
foreach (var queryKey in queries.AllKeys)
{
foreach (var unused in placeholders.Where(placeholder => queryKey == placeholder.Name.Trim(OpeningBrace, ClosingBrace)))
{
queries.Remove(queryKey);
var matchingPlaceholder = placeholders.FirstOrDefault(placeholder => queryKey == placeholder.Name.Trim(OpeningBrace, ClosingBrace));
if (matchingPlaceholder != null)
{
queries.Remove(queryKey);
}
}
}

Expand Down Expand Up @@ -143,7 +145,7 @@ private static void RemoveQueryStringParametersThatHaveBeenUsedInTemplate(Downst
}

private static string GetPath(string downstreamPath)
{
{
int length = downstreamPath.IndexOf(QuestionMark, StringComparison.Ordinal);
return downstreamPath[..length];
}
Expand Down

0 comments on commit 7ae47a8

Please sign in to comment.