Skip to content

Commit

Permalink
Set HttpClient BaseAddress only if not default
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Frohlich committed Mar 19, 2024
1 parent 55bf600 commit 0fac38b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/CostApi/AzureCostApiRetriever.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,12 @@ private async Task<HttpResponseMessage> ExecuteCallToCostApi(bool includeDebugOu
AnsiConsole.Write(new JsonText(JsonSerializer.Serialize(payload)));
AnsiConsole.WriteLine();
}

_client.BaseAddress = new Uri(CostApiAddress);


if (!string.Equals(_client.BaseAddress?.ToString(), CostApiAddress))
{
_client.BaseAddress = new Uri(CostApiAddress);
}

var options = new JsonSerializerOptions
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
Expand Down
7 changes: 5 additions & 2 deletions src/CostApi/AzurePriceRetriever.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ public AzurePriceRetriever(IHttpClientFactory httpClientFactory)

public async Task<IEnumerable<PriceRecord>> GetAzurePricesAsync(string currencyCode = "USD", string? filter = null)
{
_client.BaseAddress = new Uri(PriceApiAddress);

if (!string.Equals(_client.BaseAddress?.ToString(), PriceApiAddress))
{
_client.BaseAddress = new Uri(PriceApiAddress);
}

var prices = new List<PriceRecord>();
string? url = "api/retail/prices?api-version=2023-01-01-preview&currencyCode='" + currencyCode + "'";

Expand Down

0 comments on commit 0fac38b

Please sign in to comment.