Skip to content

Commit cd5489d

Browse files
claudiamurialdoclaudiamurialdo
andcommitted
Avoid appending URL separator if HttpClient.BaseURL is already final (#1198)
* An extra / was incorrectly appended when HttpClient.BaseURL already contained the final URL * Add unit test. --------- Co-authored-by: claudiamurialdo <c.murialdo@globant.com> (cherry picked from commit f6b2c18)
1 parent f293a4e commit cd5489d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

dotnet/src/dotnetframework/GxClasses/Domain/GxHttpClient.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,9 @@ public string GetRequestURL(string name)
14601460
}
14611461
else
14621462
{
1463-
if (!string.IsNullOrEmpty(name) && name.IndexOf('/') == 0)
1463+
if (string.IsNullOrEmpty(name))
1464+
return _url;
1465+
else if (name.IndexOf('/') == 0)
14641466
return _url + name;
14651467
else
14661468
return _url + "/" + name;

dotnet/test/DotNetUnitTest/Domain/GxHttpClientTest.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ public class GxHttpClientTest
2323
public GxHttpClientTest() {
2424
Environment.SetEnvironmentVariable("GX_HTTPCLIENT_MAX_PER_ROUTE", MAX_CONNECTIONS.ToString(), EnvironmentVariableTarget.Process);
2525
}
26+
[Fact]
27+
public void HttpClientEmptyURLOnExecute()
28+
{
29+
using (GxHttpClient client = new GxHttpClient())
30+
{
31+
client.Host = "api.saia.ai";
32+
client.BaseURL = "/v1/forecast?timezone=America%2FMontevideo";
33+
string requestUrl = client.GetRequestURL(string.Empty);
34+
Assert.EndsWith("Montevideo", requestUrl, StringComparison.Ordinal);
35+
}
36+
}
37+
2638
[Fact]
2739
public void AddHeaderWithSpecialCharactersDoesNotThrowException()
2840
{

0 commit comments

Comments
 (0)